【发布时间】:2017-08-30 11:22:49
【问题描述】:
当我使用以下代码在 volley 中调用 post 服务但我使用得到响应时
E/VOLLEY:com.android.volley.NetworkResponse@3d5dc44
try {
RequestQueue requestQueue = Volley.newRequestQueue(this);
String URL = "url";
final String requestBody = "mutation M {" + "logIn" + "(" +
"countryCode:" + "\"" + "1" + "\"" +
"deviceType:" + "\"" + "Android" + "\"" +
"osVerison:" + "\"" + "5.1.1" + "\"" +
"appVerison:" + "\"" + "2.9" + "\"" +
"currentCountry:" + "\"" + "IND" + "\"" +
"language:" + "\"" + "ENG" + "\"" +
"deviceModal:" + "\"" + "ASUS" + "" +
"\")" + "{_id,countryCode,phoneNumber,emailAddress,profilePic}";
StringRequest stringRequest = new StringRequest(Request.Method.POST, URL, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.e("VOLLEY", response);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e("VOLLEY", error.toString());
}
}) {
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String, String> params = new HashMap<String, String>();
params.put("Cache-Control","no-cache");
params.put("Content-type", "application/graphql");
return params;
}
@Override
public byte[] getBody() throws AuthFailureError {
try {
return requestBody == null ? null : requestBody.getBytes("utf-8");
} catch (UnsupportedEncodingException uee) {
VolleyLog.wtf("Unsupported Encoding while trying to get the bytes of %s using %s", requestBody, "utf-8");
return null;
}
}
@Override
protected Response<String> parseNetworkResponse(NetworkResponse response) {
String responseString = "";
if (response != null) {
responseString = response.toString();
// can get more details such as response.headers
}
return Response.success(responseString, HttpHeaderParser.parseCacheHeaders(response));
}
};
requestQueue.add(stringRequest);
} catch (Exception e) {
e.printStackTrace();
}
我是 volley 的新手,请帮助我进行改造,但我想在 volley 中使用。
【问题讨论】:
-
您能否发送您用于请求的 URL。 ?
-
我找到了解决方案,我已经在那里发布了stackoverflow.com/a/45959384/6749161