我花了很多时间阅读所有问题和答案,但无法解决问题。 android volley client的源代码:
JSONObject js = new JSONObject();
try {
JSONObject jsonobject_one = new JSONObject();
jsonobject_one.put("mobileNumber", "mobileNumberValue");
jsonobject_one.put("x", "I");
JSONObject jsonobject_TWO = new JSONObject();
jsonobject_TWO.put("value", "event");
JSONObject jsonobject = new JSONObject();
jsonobject.put("requestinfo", jsonobject_TWO);
jsonobject.put("request", jsonobject_one);
js.put("data", jsonobject.toString());
}catch (JSONException e) {
e.printStackTrace();
}
JsonObjectRequest strRequest = new JsonObjectRequest(Request.Method.POST, Server_Urls.URL_SEND_MOBILE_NUMBER,
js, new Response.Listener<JSONObject>()
{
@Override
public void onResponse(JSONObject response)
{
//Toast.makeText(getApplicationContext(), response, Toast.LENGTH_SHORT).show();
}
},
new Response.ErrorListener()
{
@Override
public void onErrorResponse(VolleyError error)
{
//Toast.makeText(getApplicationContext(), error.toString(), Toast.LENGTH_SHORT).show();
NetworkResponse networkResponse = error.networkResponse;
if (networkResponse != null && networkResponse.statusCode == HttpStatus.SC_UNAUTHORIZED) {
// HTTP Status Code: 401 Unauthorized
}
}
})
{
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
HashMap<String, String> headers = new HashMap<String, String>();
headers.put("Content-Type", "application/json");
return headers;
}
};
AppController.getInstance().addToRequestQueue(strRequest);
jersey webservice的源代码:
@POST
@Path("get_activation_code")
@Produces(MediaType.APPLICATION_JSON )
@Consumes(MediaType.APPLICATION_JSON)
public HashMap<String, String> getActivationCode(JSONObject param1){
HashMap<String, String> params = new HashMap<String, String>();
params.put("mobileNumber", "1234");
params.put("x", "x");
return params;
}
logcat的:
08-28 20:24:32.910 3282-3303 / com.hb.app I / qtaguid:标记套接字 带有标签1e7db22900000000(511554089)的47用于uid -1失败errno = -2 08-28 20:24:32.930 3282-3303 / com.hb.app I / NetworkManagementSocketTagger:tagSocketFd(47,511554089,-1)失败 与errno-2 08-28 20:24:33.650 3282-3303 / com.hb.app I / qtaguid: 未插入插座47失败errno = -2 08-28 20:24:33.650
3282-3303 / com.hb.app W / NetworkManagementSocketTagger:untagSocket(47) errno -2 08-28 20:24:33.842 3282-3303 / com.hb.app失败了 D / Volley:[95] BasicNetwork.logSlowRequests:HTTP响应 request =&lt; [] http://10.0.2.2:8080/GmServer/gme/registration/get_activation_code 0x1e7db229正常1&gt; [lifetime = 8875],[size = 6441],[rc = 500], [retryCount = 0] 08-28 20:24:33.884 3282-3303 / com.hb.app E / Volley: [95] BasicNetwork.performRequest:意外的响应代码500 http://10.0.2.2:8080/GMServer/gme/registration/get_activation_code 08-28 20:24:40.743 3282-3282 / com.hb.app D / Volley:[1] Request.finish:33086 ms:[] http://10.0.2.2:8080/GMeServer/giftme/registration/get_activation_code 0x1e7db229 NORMAL 1
请注意,我在StackOverflow中尝试了几乎所有等效的问题而没有回答。