0
我發送POST
查詢以及來自android設備的字符串數據使用Volley
庫。Android Volley:在服務器接收到的空值是用POST請求發送的字符串參數
但是,服務器僅收到參數的null
值。我的代碼是這樣的:
final String param1 = "one";
final String param2 = "124843";
final String param3 = "878942";
final String param4 = "885942";
String url = getIPAddr()+":"+getPort()+"/com.va.jersey.helloworld/hello";
RequestQueue queue = Volley.newRequestQueue(getBaseContext());
StringRequest stringRequest = new StringRequest(Request.Method.POST,url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
showOutput(response);
}
},new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
showOutput(error.toString());
}
}){
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> params = new HashMap<String, String>();
params.put("param1", param1);
params.put("param2", param2);
params.put("param3", param3);
params.put("param3", param4);
return params;
} //attaching POST params
};
queue.add(stringRequest);
我相信這是在StringRequest
一些錯誤,歡迎指正......
錯誤:org.json.JSONException:類型java.lang.String的值nullnullnullnull無法轉換爲JSONObject –
您能否只給我一個您正在調用的url? –
另一個帖子在SO'http:// stackoverflow.com/questions/28135008/unexpected-response-code-500-for-post-method'講述了在ObjectRequest中用'something替換'null'不明白)... –