[英]can't send params to server using volley
我不知道为什么我不能使用volley将参数发送到服务器,我的问题是当我试图使用velley发送参数时,我将这个错误发送到我的logcat,
[149] BasicNetwork.performRequest: Unexpected response code 403 for http://localhost/test/post.php
每个人都可以帮助我解决这个问题吗?
我的PHP服务器:
<?php
if (isset($_POST['action'])){
$action = $_POST['action'];
} else {
echo "Invalid Data";
exit;
}
if($action="read"){
echo "read";
}
?>
我的请求 :
String tag_string_req = "string_req";
String url = "http://localhost/test/post.php";
StringRequest strReq = new StringRequest(Request.Method.POST,
url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.d("TAG", response.toString());
Log.d("LOG", "success");
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
VolleyLog.d("TAG", "Error: " + error.getMessage());
}
}){
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> params = new HashMap<String, String>();
params.put("action", "read");
return params;
}
};
AppController.getInstance().addToRequestQueue(strReq, tag_string_req);
我认为问题是您的URL参数。 “本地主机”是一个与设备本身连接的单词,您的服务器无法在该设备上运行。 而不是localhost,您需要编写运行服务器的计算机的IP。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.