大家好我正在使用Volley并尝试从SOAP api解析数据。以下是我的代码段代码,当我尝试解析数据时出现错误。谁能帮我这个?我每次都会收到以下错误消息。
E / Volley:[7440] BasicNetwork.performRequest:意外响应 代码400 for
public void HttpPOSTRequestWithParam() {
RequestQueue queue = Volley.newRequestQueue(this);
String url = "https://www.myweb.co.ke/Wt/webtask.asmx?op=GetProductListing";
StringRequest postRequest = new StringRequest(Request.Method.POST, url,
new Response.Listener<String>()
{
@Override
public void onResponse(String response) {
Log.e("Response", response);
}
},
new Response.ErrorListener()
{
@Override
public void onErrorResponse(VolleyError error) {
Log.e("ERROR","error => "+error.toString());
}
}
) {
@Override
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<String, String>();
params.put("UserName", "John");
return params;
}
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String, String> params = new HashMap<String, String>();
params.put("User Name", "1234");
params.put("Password", "4321");
return params;
}
};
queue.add(postRequest);}
答案 0 :(得分:0)
您可能需要告诉它Content-Type和Accept标头的编码方式。这里的参数字符串应如下所示: 'grant_type = password&username = apikey&password = apipassword'
@Override
protected Map<String, String> getParams()
{
Map<String, String> params = new HashMap<String, String>();
params.put("grant_type", "password");
params.put("username", "apikey");
params.put("password", "apipassword");
return params;
}
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
HashMap<String, String> headers = new HashMap<String, String>();
headers.put("Accept", "application/x-www-form-urlencoded; charset=UTF-8");
headers.put("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
return headers;
}