这就是我发送请求的方式
// Tag used to cancel the request
String tag_json_obj = "string_req";
String url = getResources().getString(R.string.ybase_path)+"strings_u.php";
String tag_string_req = "req_login";
StringRequest stringRequest = new StringRequest(Request.Method.GET, url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Toast.makeText(getActivity(), response.toString(),
Toast.LENGTH_LONG).show();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError volleyError) {
}
}) {
@Override
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<String, String>();
params.put("a_id", application_id);
return params;
}
@Override
public Map<String, String> getHeaders(){
HashMap<String, String> headers = new HashMap<String, String>();
headers.put("Content-Type", "text/html");
//headers.put("apiKey", "xxxxxxxxxxxxxxx");
return headers;
}
};
AppController.getInstance().addToRequestQueue(stringRequest,tag_string_req);
在服务器端我正在处理请求
if(isset($_GET['a_id']))
但似乎参数不是仅发送的。我两天都没有运气,一直在寻找解决方案。
答案 0 :(得分:2)
您需要使用Request.Method.POST
代替Request.Method.GET
来发送参数
StringRequest stringRequest = new StringRequest(Request.Method.POST, url,
// ^^^^
更新:您应该使用if(isset($_POST['a_id']))
代替if(isset($_GET['a_id']))