而在Android上使用凌空服务器没有收到JSON对象 [英] Server does not receive JSON object while using volley on android
问题描述
我试图用凌空JSON对象发送到服务器,并得到回应,但似乎在服务器犯规获得数据。
I tried to use volley to send JSON object to server and get a response but it seems the server doesnt get the data.
如果我试图只是回显它的工作原理,但如果我尝试读取服务器上的JSON对象,并作出反应,我得到凌空错误。我也试着回显JSON对象,并仍然得到错误。
当我使用的Htt prequest一切工作正常。
我加了相同的标题,如在Htt的prequest和截击,也许连接到UTF8?这是我在做setEntity
If i tried to just echo back it works, but if i try to read the JSON object on server and react, i get error on volley. I also try to echo back the JSON object and still get error. When i use HttpRequest everything works ok. I added the same Headers as in HttpRequest and Volley, Maybe is connected to UTF8? which i do on setEntity
我得到关于PHP中的数据是这样的:
i get the data on PHP like this:
$data = json_decode(file_get_contents('php://input'), true);
我的凌空code:
My volley code:
JsonObjectRequest req = new JsonObjectRequest(Request.Method.POST,
URL, jsonObject ,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.d(TAG,"Response: " + response.toString());
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
VolleyLog.e("Error: ", error.getMessage());
}
})
{
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String, String> params = new HashMap<String, String>();
params.put("Accept", "application/json");
params.put("Content-Type", "application/json");
return params;
}
};
;
人有一个想法?
推荐答案
原来,我凌空code是确定的。问题是在服务器侧
It turned out that my volley code was ok. the problem was on the server side.
使用Breadbin评论和更换用error.printStackTrace()的VolleyLog.e帮助查找问题。
Using Breadbin comment and replacing the VolleyLog.e with error.printStackTrace() helped to find the problem.
这篇关于而在Android上使用凌空服务器没有收到JSON对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!