所以我想打印響應的結果,然後使用gson爲模型生成數據,但響應永遠不會返回onResponse被調用。Volley Post請求返回沒有響應裏面onResponse
如果您發現Logcat,則onResponse中的log.i未顯示..!?但在使用此請求的Activity的onSuccess內部,它通常會顯示日誌,但是如果日誌包含響應對象,則它不會顯示哪個非常奇怪,也沒有任何意義。
logcat的
I/getUrl:: http://1925.232.55/login.php
I/getParams:: {username =samy, password=123456}
D/libc: [NET] android_getaddrinfofornetcontext+,hn 20(0x6),sn(),hints(known),family 0,flags 1024, proc=com...
D/libc: [NET] android_getaddrinfo_proxy get netid:0
D/libc: [NET] android_getaddrinfo_proxy-, success
I/onSuccess:: check /* this log inside the Activity which uses this request */
I tried test the request using PostMan with the same url and params and it returns json response normally..?
郵差響應
{
"status": "success",
"user_id": "10",
"user_name": "samy",
"full_name": "samy samy",
"picture": "st_pictures/IMG_085207.jpg",
"level": "1",
"school": "NY School",
"city": "NY",
"class": "6",
"age": "22",
"teacher": "2",
"token": "f808e758sdfsdfsf162dbdfcf88e3dc8a96"
}
請求代碼
final RequestQueue queue = Volley.newRequestQueue(context);
final StringRequest sr = new StringRequest(Request.Method.POST, getLoginURL(), new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.i("onResponse: ", response + "");
requestResult.onSuccess(response);
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
requestResult.onFail(error);
VolleyLog.e("Error: ", error.getMessage());
error.printStackTrace();
}
})
{
@Override
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<String, String>();
params.put("username ", un);
params.put("password", pass);
Log.i("getParams: ", params.toString());
return params;
}
@Override
public byte[] getBody() throws AuthFailureError {
Log.i("getUrl: ",getUrl());
return super.getBody();
}
}
;
queue.add(sr);
UPDATE#1
URL http://clients.intertech.ps/raz/std.php
E/Volley: [1] 2.onErrorResponse: Error:
W/System.err: com.android.volley.ParseError: org.json.JSONException: End of input at character 0 of
W/System.err: at com.android.volley.toolbox.JsonObjectRequest.parseNetworkResponse(JsonObjectRequest.java:73)
W/System.err: at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:123)
W/System.err: Caused by: org.json.JSONException: End of input at character 0 of
W/System.err: at org.json.JSONTokener.syntaxError(JSONTokener.java:449)
W/System.err: at org.json.JSONTokener.nextValue(JSONTokener.java:97)
W/System.err: at org.json.JSONObject.<init>(JSONObject.java:156)
W/System.err: at org.json.JSONObject.<init>(JSONObject.java:173)
W/System.err: at com.android.volley.toolbox.JsonObjectRequest.parseNetworkResponse(JsonObjectRequest.java:68)
W/System.err: ... 1 more
第一日誌'http://1925.232.55/login.php'我認爲你的網址是錯誤的 –
@OussemaAroua這是一個虛擬的一個,你想讓我用它替換它嗎? –
沒有必要我只是cheking,如果它是真實的或不 –