Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/205.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中使用Volley将JSON数组体发布到.NETWeb服务_Android_Json_Web Services_Http Post_Android Volley - Fatal编程技术网

在Android中使用Volley将JSON数组体发布到.NETWeb服务

在Android中使用Volley将JSON数组体发布到.NETWeb服务,android,json,web-services,http-post,android-volley,Android,Json,Web Services,Http Post,Android Volley,我试图在Android中使用截击发布一个JSON正文,在花了很多小时都没有成功之后,我正在写这个问题 下面是我的代码片段 StringRequest residentSyncRequest = new StringRequest(Request.Method.POST, Commons.URL,this,this,ADD_REQ){ @Override public Map<String, String> getHeaders() throws AuthFailure

我试图在Android中使用截击发布一个JSON正文,在花了很多小时都没有成功之后,我正在写这个问题

下面是我的代码片段

StringRequest residentSyncRequest = new StringRequest(Request.Method.POST, Commons.URL,this,this,ADD_REQ){
    @Override
    public Map<String, String> getHeaders() throws AuthFailureError {

        HashMap<String,String> params = new HashMap<String, String>();
        params.put("Content-Type","application/json");

        return params;
    }

    @Override
    public byte[] getBody() throws AuthFailureError {
        JSONArray jsonArray = new JSONArray();
        JSONObject jsonObject = new JSONObject();

        SharedPreferences sharedPreferences = getActivity().getSharedPreferences(Commons.PREF_NAME, Context.MODE_PRIVATE);

        try {
            jsonObject.put("RowID","0");
            jsonObject.put("LocalID","100");
            jsonObject.put("LoginUserID",sharedPreferences.getString(Commons.pref_loginUserId,""));                      
            jsonObject.put("AppToken",sharedPreferences.getString(Commons.pref_appToken,""));

        } catch (JSONException e) {
            e.printStackTrace();
        }

        jsonArray.put(jsonObject);

        return jsonArray.toString().getBytes();
    }
};
VollyRequest.getRequestQueue(getActivity()).add(residentSyncRequest);
我尝试使用postman chrome扩展名调用相同的web服务,该服务工作正常

不确定在返回
字节[]
之前是否需要进行任何编码

请帮忙


提前感谢。

Volley默认情况下将所有post参数作为JSON值,因此,您只需要使用一个请求,而不是StringRequest,只需添加所有要作为常规post值发布的JSON值。

Volley不支持像JsonObject请求那样直接发布JsonArray请求。希望他们能在下一版本中添加此函数,因为有很多api只提供JsonArray

编辑:

其实有一个解决办法

E/Volley﹕ [255] BasicNetwork.performRequest: Unexpected response code 400 for ...