Php 用Android中的凌空库向服务器发送数据(POST或GET)

Php 用Android中的凌空库向服务器发送数据(POST或GET),php,android,android-volley,Php,Android,Android Volley,我开发了一个应用程序,我将通过Json将数据从手机发送到服务器,为此我使用Android中的Volley库。 但是我不能向服务器发送数据 我的简单php代码: $name = $_GET["name"]; $j = array('name' =>$name); echo json_encode($j); 我的java代码: private void makeJsonObjectRequest() { mRequestQueue = Volley.newReques

我开发了一个应用程序,我将通过
Json
将数据从手机发送到服务器,为此我使用Android中的
Volley
库。
但是我不能向服务器发送数据

我的简单php代码:

$name = $_GET["name"];
$j = array('name' =>$name);
echo json_encode($j);
我的java代码:

    private void makeJsonObjectRequest() {
        mRequestQueue = Volley.newRequestQueue(this);
        String url = "http://my-site-name/sampleGET.php";

        StringRequest jsonObjReq = new StringRequest(
            Request.Method.GET, 
            url,
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    Log.d("result:", response);
                    Toast.makeText(getApplicationContext(), response, Toast.LENGTH_SHORT).show();
                }
            }, 
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    VolleyLog.d("err", "Error: " + error.getMessage());
                    makeJsonObjectRequest();
                }
            }
        ){
            @Override
            protected Map<String, String> getParams() {
                Map<String, String> params = new HashMap<>();
                params.put("name", "json");
                return params;
            }
        };
        mRequestQueue.add(jsonObjReq);
    }
private void makeJsonObjectRequest(){
mRequestQueue=Volley.newRequestQueue(this);
字符串url=”http://my-site-name/sampleGET.php";
StringRequest jsonObjReq=新StringRequest(
Request.Method.GET,
网址,
新的Response.Listener(){
@凌驾
公共void onResponse(字符串响应){
Log.d(“结果:”,响应);
Toast.makeText(getApplicationContext(),response,Toast.LENGTH_SHORT.show();
}
}, 
新的Response.ErrorListener(){
@凌驾
公共无效onErrorResponse(截击错误){
d(“err”,“Error:+Error.getMessage());
makeJsonObjectRequest();
}
}
){
@凌驾
受保护的映射getParams(){
Map params=新的HashMap();
参数put(“名称”、“json”);
返回参数;
}
};
mRequestQueue.add(jsonObjReq);
}
它还从以下链接获得了帮助:

但仍然无法使用它,无法将数据(POST或GET)从手机发送到服务器
我怎样才能做到这一点?

从当前代码中删除此方法:

        @Override
        protected Map<String, String> getParams() {
            Map<String, String> params = new HashMap<>();
            params.put("name", "json");
            return params;
        }
然后在php中解码json数据:

    $jsonRequest = json_decode(stream_get_contents(STDIN));
    var_dump($jsonRequest);

如果需要更多信息,请告诉我。

如果网络连接失败,您将进入一个递归循环-remove makeJsonObjectRequest();-在OneErrorResponse方法中。没有任何日志等。我倾向于说您可以尝试使用$\u SERVER[“name”]而不是$\u GET[“name”]
    $jsonRequest = json_decode(stream_get_contents(STDIN));
    var_dump($jsonRequest);