使用Android Volley的HTTPS请求
问题描述:
我想通过POST提交一个HTTPS请求,但它不起作用。该请求带我到onErrorResponse,但没有显示错误是什么。我用邮差测试,它工作正常。 我离开了我的部分代码。使用Android Volley的HTTPS请求
Map<String, String> params = new HashMap<String, String>();
params.put(PARAM_HASH_TOKEN, HASH_TOKEN);
params.put(PARAM_USUARIO, id);
params.put(PARAM_PASSWORD, password);
JSONObject jsonBody = new JSONObject(params);
Log.e("POST",jsonBody.toString());
JsonObjectRequest mJsonObjectRequest = new JsonObjectRequest(Request.Method.POST, URL_API, jsonBody, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
if (response != null) {
F_PARSEAR_JSON_RESPUESTA(response);
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
String msg = (error.getMessage() == null) ? "Ha ocurrido un error, intentelo de nuevo." : error.getMessage();
Log.e("ERROR",URL_API);
Log.e("ERROR",msg);
_loginButton.setEnabled(true);
}
});
ApplicationLoader.getInstance().addToRequestQueue(mJsonObjectRequest);
答
您可以检查客户端和服务器中的内容类型吗?它们具有相似的价值。
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
HashMap<String, String> headers = new HashMap<String, String>();
headers.put("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
return headers;
}
@Override
public String getBodyContentType()
{
return "application/json";
}
我希望它能帮助你!
+0
不起作用=(,认为ssl证书不受信任 – user3281600
+0
我遇到过类似的错误,您尝试测试其他内容类型。 – Thientvse
你是什么意思,不显示错误?你在调试器中运行并确认它是空的吗? –
@sam_c没错,我正在使用调试器,并没有显示错误。 – user3281600