Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/187.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 服务器未显示POST数据_Android_Node.js_Express_Android Volley - Fatal编程技术网

Android 服务器未显示POST数据

Android 服务器未显示POST数据,android,node.js,express,android-volley,Android,Node.js,Express,Android Volley,我使用这段代码将POST数据(一个JSON对象)发送到我的Node/Express.js服务器。我使用了body解析器,服务器从StringRequests接收数据时没有问题,但是当我发送一个JsonArrayRequest时,console.log(request.body)的输出;是{} RequestBin接收到POST数据并正确显示 我尝试使用HashMap将content-type:application/json添加到POST请求的头中,这是向另一个有类似问题的人推荐的,但对我来说不

我使用这段代码将POST数据(一个JSON对象)发送到我的Node/Express.js服务器。我使用了body解析器,服务器从StringRequests接收数据时没有问题,但是当我发送一个JsonArrayRequest时,console.log(request.body)的输出;是{}

RequestBin接收到POST数据并正确显示

我尝试使用HashMap将content-type:application/json添加到POST请求的头中,这是向另一个有类似问题的人推荐的,但对我来说不起作用。它仍然没有显示出来

我只使用了body解析器和带有Node.js 0.12的Express插件。有什么想法吗

public void SearchFor(final String placetype, final String placelocation) throws JSONException {
        String url = "http://requestb.in/113ewl01";
        JSONObject PlaceObj = new JSONObject();
        JSONArray PlJarr = new JSONArray();
        PlaceObj.put("PlaceType", placetype);
        PlaceObj.put("PlaceLocation", placelocation);

        //PlJarr.put(PlaceObj);
        RequestQueue PlaceQueue = Volley.newRequestQueue(this);

        JsonArrayRequest PlaceArrayRequest = new JsonArrayRequest(Request.Method.POST, url, PlJarr, new Response.Listener<JSONArray>() {
            @Override
            public void onResponse(JSONArray response) {
                int i;
                ArrayList<String> MArrList = new ArrayList<>();
                ArrayList<String> PlaceList = new ArrayList<>();

                for (i = 0; i < response.length(); i++) {
                    try {
                        MArrList.add(response.get(i).toString());
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
                JSONObject PlaceParser = null;
                try {
                    for (i = 0; i < response.length(); i++) {
                        PlaceParser = new JSONObject(MArrList.get(i));
                        PlaceList.add(PlaceParser.get("PlaceName").toString() + "\n" + "Estimated Price: $" + PlaceParser.get("EstimatedPrice").toString() + ".\n" + PlaceParser.get("PlaceAddress").toString() + "\n" + PlaceParser.get("OtherDetails").toString());
                        hybridlist[i] = "$" + PlaceParser.get("EstimatedPrice").toString() + " - " + PlaceParser.get("PlaceName").toString();
                    }

                } catch (JSONException e) {
                    e.printStackTrace();
                }
                DisplayHotels(PlaceList);
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                Context context = getApplicationContext();
                Toast VerrorToast = Toast.makeText(context, "Connection failed.", Toast.LENGTH_LONG);
                VerrorToast.show();
            }
        }) {
            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                HashMap<String, String> HeadMap = new HashMap<String, String>();
                HeadMap.put("Content-Type", "application/json");
                HeadMap.put("charset", "utf-8");
                return HeadMap;
            }

        };

        PlaceQueue.add(PlaceArrayRequest);
    }
public void SearchFor(final String placetype,final String placelocation)抛出JSONException{
字符串url=”http://requestb.in/113ewl01";
JSONObject PlaceObj=新的JSONObject();
JSONArray PlJarr=新的JSONArray();
PlaceObj.put(“PlaceType”,PlaceType);
PlaceObj.put(“PlaceLocation”,PlaceLocation);
//PlJarr.put(PlaceObj);
RequestQueue PlaceQueue=Volley.newRequestQueue(this);
JsonArrayRequest PlaceArrayRequest=newjsonarrayrequest(Request.Method.POST、url、PlJarr、newresponse.Listener()){
@凌驾
公共void onResponse(JSONArray响应){
int i;
ArrayList MArrList=新的ArrayList();
ArrayList PlaceList=新的ArrayList();
对于(i=0;i
不过,该RequestBin url可能已经过期

谢谢

编辑-我更新了上面的代码。我只是将我的JSONObject放入一个JSONArray,然后发送JSONArray,并使用HashMap添加头,但是服务器打印相同的“{}”

以下是RequestBin从应用程序收到的内容的屏幕截图:


您正在
JSONArray
请求中发送
JSONObject
。您需要发送一个
JSONObject
数组s@AndrewBreen我把它改成了JSONArray,但同样的事情发生了(