Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/233.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 Voley-BasicNetwork.performRequest:意外响应代码400(5)_Android_Arrays_Android Volley - Fatal编程技术网

Android Voley-BasicNetwork.performRequest:意外响应代码400(5)

Android Voley-BasicNetwork.performRequest:意外响应代码400(5),android,arrays,android-volley,Android,Arrays,Android Volley,我有以下代码从服务器调用jsonArray: String urlJsonObj = "http://myip/Services/ServiceOne.asmx/Search?name="+ searchValue + "" ; JsonArrayRequest jsonObjReq = new JsonArrayRequest(urlJsonObj, new Response.Listener<JSONArray>() {

我有以下代码从服务器调用jsonArray:

 String urlJsonObj = "http://myip/Services/ServiceOne.asmx/Search?name="+ searchValue + "" ;

    JsonArrayRequest jsonObjReq = new JsonArrayRequest(urlJsonObj,
            new Response.Listener<JSONArray>() {
                @Override
                public void onResponse( JSONArray response) {
                    Log.d(TAG, response.toString());
                    pDialog.hide();
                }
            }, new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError error) {
            VolleyLog.d(TAG, "Error: " + error.getMessage());
            pDialog.hide();
        }
    }) {

        @Override
        public Map<String, String> getHeaders() throws AuthFailureError {
            HashMap<String, String> headers = new HashMap<String, String>();
            headers.put("Content-Type", "application/json; charset=utf-8");
            return headers;
        }

    };

    /// Adding JsonObject request to request queue
    AppController.getInstance().addToRequestQueue(jsonObjReq);
字符串urlJsonObj=”http://myip/Services/ServiceOne.asmx/Search?name=“+searchValue+”;
JsonArrayRequest JSONOBJEQ=新的JsonArrayRequest(urlJsonObj,
新的Response.Listener(){
@凌驾
公共void onResponse(JSONArray响应){
Log.d(TAG,response.toString());
pDialog.hide();
}
},new Response.ErrorListener(){
@凌驾
公共无效onErrorResponse(截击错误){
d(标记“Error:+Error.getMessage());
pDialog.hide();
}
}) {
@凌驾
公共映射getHeaders()引发AuthFailureError{
HashMap headers=新的HashMap();
headers.put(“内容类型”、“应用程序/json;字符集=utf-8”);
返回标题;
}
};
///将JsonObject请求添加到请求队列
AppController.getInstance().addToRequestQueue(JSONOBJEQ);
这是预期结果(由邮递员测试):

[ { “RaisonSocialId”:6108, “RaisonSocial”:“企业100”, “地址”:“Mamie Wata街100号”, “电话号码”:“425 438 944”, “状态”:0, “消息”:空 }, { “RaisonSocialId”:7008, “RaisonSocial”:“企业1000”, “地址”:“Mamie Wata街1000号”, “电话号码”:“167874826”, “状态”:0, “消息”:空 }, { “RaisonSocialId”:7009, “RaisonSocial”:“Enterprise 1001”, “地址”:“Mamie Wata街1001号”, “电话号码”:“29959556”, “状态”:0, “消息”:空 }, { “RaisonSocialId”:7010, “RaisonSocial”:“企业1002”, “地址”:“Mamie Wata街1002号”, “电话号码”:“559 751 823”, “状态”:0, “消息”:空 } ]

错误日志;
BasicNetwork.performRequest:30的意外响应代码400


我是否遗漏了一些内容?

尝试使用
StringRequest
并在
getParams()函数中发送参数

代码:

stringurl=”http://myip/Services/ServiceOne.asmx/Search";
StringRequest sr=new StringRequest(Request.Method.POST,url,new Response.Listener()){
@凌驾
公共void onResponse(字符串响应){
Log.d(TAG,response.toString());
pDialog.hide();
}
},new Response.ErrorListener(){
@凌驾
公共无效onErrorResponse(截击错误){
//错误
d(标记“Error:+Error.getMessage());
pDialog.hide();
}
}) {
@凌驾
受保护的映射getParams(){
Map params=新的HashMap();
参数put(“名称”,搜索值);
返回参数;
}
@凌驾
公共映射getHeaders()引发AuthFailureError{
HashMap headers=新的HashMap();
headers.put(“内容类型”、“应用程序/json;字符集=utf-8”);
返回标题;
}
};

尝试使用
StringRequest
并在
getParams()
函数中发送参数

代码:

stringurl=”http://myip/Services/ServiceOne.asmx/Search";
StringRequest sr=new StringRequest(Request.Method.POST,url,new Response.Listener()){
@凌驾
公共void onResponse(字符串响应){
Log.d(TAG,response.toString());
pDialog.hide();
}
},new Response.ErrorListener(){
@凌驾
公共无效onErrorResponse(截击错误){
//错误
d(标记“Error:+Error.getMessage());
pDialog.hide();
}
}) {
@凌驾
受保护的映射getParams(){
Map params=新的HashMap();
参数put(“名称”,搜索值);
返回参数;
}
@凌驾
公共映射getHeaders()引发AuthFailureError{
HashMap headers=新的HashMap();
headers.put(“内容类型”、“应用程序/json;字符集=utf-8”);
返回标题;
}
};

使用下面的代码从服务器获取响应,同时更改您的请求类型GET/POST

 StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    Log.v("response",""+response);
                    if(response!=null){
                        try {
                   //write your json parsing code here
                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    VolleyLog.d("TAG", "Error: " + error.getMessage());
                    Log.v("error",""+error);
                }
            }){
@Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                HashMap<String, String> headers = new HashMap<String, String>();
                headers.put("Content-Type", "application/json; charset=utf-8");
            return headers;
        }
       @Override            
           protected Map<String,String> getParams(){
            Map<String,String> params = new HashMap<String, String>();


            return params;
        }

    };
StringRequest StringRequest=新的StringRequest(Request.Method.GET,url,
新的Response.Listener(){
@凌驾
公共void onResponse(字符串响应){
Log.v(“响应”,“响应+响应”);
if(响应!=null){
试一试{
//在这里编写json解析代码
}
}捕获(JSONException e){
e、 printStackTrace();
}
}
}
},
新的Response.ErrorListener(){
@凌驾
公共无效onErrorResponse(截击错误){
d(“TAG”,“Error:+Error.getMessage());
Log.v(“错误”,“错误+错误”);
}
}){
@凌驾
公共映射getHeaders()引发AuthFailureError{
HashMap headers=新的HashMap();
headers.put(“内容类型”、“应用程序/json;字符集=utf-8”);
返回标题;
}
@凌驾
受保护的映射getParams(){
Map params=新的HashMap();
返回参数;
}
};

使用下面的代码从服务器获取响应,同时更改您的请求类型GET/POST

 StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    Log.v("response",""+response);
                    if(response!=null){
                        try {
                   //write your json parsing code here
                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    VolleyLog.d("TAG", "Error: " + error.getMessage());
                    Log.v("error",""+error);
                }
            }){
@Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                HashMap<String, String> headers = new HashMap<String, String>();
                headers.put("Content-Type", "application/json; charset=utf-8");
            return headers;
        }
       @Override            
           protected Map<String,String> getParams(){
            Map<String,String> params = new HashMap<String, String>();


            return params;
        }

    };
StringRequest StringRequest=新的StringRequest(Request.Method.GET,url,
新的Response.Listener(){
@凌驾
公共void onResponse(字符串响应){
Log.v(“响应”,“响应+响应”);
if(响应!=null){
试一试{
//在这里编写json解析代码
}
}捕获(JSONException e){
 String urlJsonObj= "http://myip/Services/ServiceOne.asmx/Search?name=entreprise";
 JsonArrayRequest request = new JsonArrayRequest(urlJsonObj,
            new Response.Listener<JSONArray>() {
                @Override
                public void onResponse(JSONArray jsonArray) {
                    Log.d("TAG_JSON_ARRAY", jsonArray.toString());

                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError volleyError) {
                    Toast.makeText(SearchActivity.this, "Unable to fetch data: " + volleyError.getMessage(), Toast.LENGTH_SHORT).show();
                }
            });