Volley POST返回TimeoutError

时间:2015-07-24 01:48:48

标签: android http timeout android-volley

我的问题是谷歌图书馆Volley for android。我正在做HTTP帖子并获得TimeoutError。 curl的相同请求返回正常。这是网址请求(网站和密码更改)

  

curl -X POST - 数据   “调试器= curlsergiy&安培;登录ID =本身份识别码&安培;操作= SimpleLogin&安培; OutputJSON = 2及模块= DataSource的&安培;密码=输入mypassword%21安培;”   https://mobile-demo.mycompany.com/csi-requesthandler/RequestHandler

这是基于Volley的代码

void makeTest() {
        final StringRequest stringRequest = new StringRequest(Request.Method.POST, "https://mobile-demo.mycompany.com/csi-requesthandler/RequestHandler",
                new Response.Listener<String> () {
                    @Override
                    public void onResponse(String response) {
                        Log.d(TAG, "Response:" + response);
                    }
                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                        Log.d(TAG, "Volley returned error:" + error);
                            Class klass = error.getClass();
                            if(klass == com.android.volley.AuthFailureError.class) {
                                Log.d(TAG,"AuthFailureError");
                            } else if(klass == com.android.volley.NetworkError.class) {
                                Log.d(TAG,"NetworkError");
                            } else if(klass == com.android.volley.NoConnectionError.class) {
                                Log.d(TAG,"NoConnectionError");
                            } else if(klass == com.android.volley.ServerError.class) {
                                Log.d(TAG,"ServerError");
                            } else if(klass == com.android.volley.TimeoutError.class) {
                                Log.d(TAG,"TimeoutError");
                            } else if(klass == com.android.volley.ParseError.class) {
                                Log.d(TAG,"ParseError");
                            } else if(klass == com.android.volley.VolleyError.class) {
                                Log.d(TAG,"General error");
                            }
                    }
                }) {
            @Override
            public byte[] getBody() throws AuthFailureError{
                return "debugger=curlsergiy&LoginID=myid&Operation=SimpleLogin&OutputJSON=2&Module=DataSource&Password=mypassword%21&".getBytes();
            }
        };
        //set timeout and retry
        stringRequest.setRetryPolicy(new DefaultRetryPolicy(5000,DefaultRetryPolicy.DEFAULT_MAX_RETRIES,DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
        stringRequest.setShouldCache(false);
        requestQueue.add(stringRequest);
    }

5秒后排球输出 TimeoutError

0 个答案:

没有答案