com.android.volley.NoConnectionError:java.net.ProtocolException:意外的状态行:HTTP/1.1 401.3未经授权 [英] com.android.volley.NoConnectionError: java.net.ProtocolException: Unexpected status line: HTTP/1.1 401.3 Unauthorized

查看:231
本文介绍了com.android.volley.NoConnectionError:java.net.ProtocolException:意外的状态行:HTTP/1.1 401.3未经授权的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是我的代码.我收到com.android.volley.NoConnectionError:java.net.ProtocolException:意外的状态行:HTTP/1.1 401.3未经授权.

    RequestQueue queue = Volley.newRequestQueue(this);
    String url = "http://echo.jsontest.com/key/value/one/two";

    JsonObjectRequest getRequest = new JsonObjectRequest(Request.Method.GET, url, (String)null,
            new Response.Listener<JSONObject>()
            {
                @Override
                public void onResponse(JSONObject response) {
                    Log.e("LOG_VOLLEY","response : "+response.toString());
                    System.out.println(response);
                    txt.setText("response : "+response.toString());
                }
            },
            new Response.ErrorListener()
            {
                @Override
                public void onErrorResponse(VolleyError error) {
                    Log.e("LOG_VOLLEY", "Error : " + error.toString());
                    System.out.println(error);
                    txt.setText("Error : " +error.toString());
                }
            } );

    queue.add(getRequest);

}

使用loopj库时出现类似错误. 这是我第一次使用排球库和http连接. 我感谢您的帮助.谢谢.

解决方案

我使用了您的代码(删除了与TextView相关的代码行),并得到了以下屏幕截图的结果(请注意logcat窗口)

The following is my code. I got com.android.volley.NoConnectionError: java.net.ProtocolException: Unexpected status line: HTTP/1.1 401.3 Unauthorized.

    RequestQueue queue = Volley.newRequestQueue(this);
    String url = "http://echo.jsontest.com/key/value/one/two";

    JsonObjectRequest getRequest = new JsonObjectRequest(Request.Method.GET, url, (String)null,
            new Response.Listener<JSONObject>()
            {
                @Override
                public void onResponse(JSONObject response) {
                    Log.e("LOG_VOLLEY","response : "+response.toString());
                    System.out.println(response);
                    txt.setText("response : "+response.toString());
                }
            },
            new Response.ErrorListener()
            {
                @Override
                public void onErrorResponse(VolleyError error) {
                    Log.e("LOG_VOLLEY", "Error : " + error.toString());
                    System.out.println(error);
                    txt.setText("Error : " +error.toString());
                }
            } );

    queue.add(getRequest);

}

I got a simmilar error when I used the loopj library. This is my first time using volley library and http connect. I appreciate your help. Thank you.

解决方案

I used your code (removed lines of code relating to TextView) and got the result as the following screenshot (pay attention to the logcat window)

这篇关于com.android.volley.NoConnectionError:java.net.ProtocolException:意外的状态行:HTTP/1.1 401.3未经授权的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆