我正在尝试以以下格式发送JsonObjectRequest (GET)参数:
m2=2
我的问题是,我应该得到一个响应-代码200 (OK),如果param1是"1“,param2是"2”。但我总是得到错误的回应代码。所以我认为,请求是以错误的格式发送的。
Map<String, String> params = new HashMap();
params.put("param1", "1");
params.put("param2", "2");
JsonObjectRequest jsObjRequest = new JsonObjectRequest
(Request.Method.GET, "http://localhost:8080/xy", new JSONObject(params), new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
// TODO Auto-generated method stub
}
});
// Access the RequestQueue through your singleton class.
QueueSingleton.getInstance(LoginActivity.this).addToRequestQueue(jsObjRequest);谢谢!
发布于 2018-01-31 19:59:42
现在,您将JsonObject(params)作为请求的主体提供,这是不正确的。我不认为Volley会将您提供的JSON对象附加到GET request...so中,您需要自己这样做。
去掉添加post正文的内容,并使用Uri.Builder.appendQueryParameter(键,值)手动在URL上添加params。
发布于 2018-01-31 20:01:38
因为您使用了GET方法,所以尝试使用url (如
int param1Value = 1, param2Value = 2;
String url = "http://localhost:8080/xy?param1=" + param1Value + "¶m2=" + param2Value;发布于 2018-01-31 20:12:27
int p1=1;
int p2= 2;
string url= "http://localhost:8080/xy?param1="+p1+"¶m2="+p2;把这个网址放进你正在使用的网址里。
https://stackoverflow.com/questions/48550421
复制相似问题