需要代理身份验证,需要翻新

时间:2018-11-01 04:11:37

标签: java android retrofit2

在翻新中进行api调用时出现此错误

  

Response {protocol = http / 1.1,code = 407,message = Proxy Authentication   必填,url = {http://example.com/test.xml}

下面是我的api调用。

 private void showProxies() {
   serviceCall = apiService.listOfServers();
    serviceCall.enqueue(new Callback<ServerListModel>() {
        @Override
        public void onResponse(Call<ServerListModel> call, Response<ServerListModel> response) {
            if (response.body() != null) {
                ArrayList<Proxies> proxyArrayList = response.body().proxiesArrayList;
                 showProxyDialog(proxyArrayList);
            }
            else
                Toast.makeText(BrowserActivity.this, "Server 407 error.", Toast.LENGTH_SHORT).show();
        }

        @SuppressLint("LongLogTag")
        @Override
        public void onFailure(Call<ServerListModel> call, Throwable t) {
            Log.e(TAG, t.toString());
        }
    });
}

2 个答案:

答案 0 :(得分:0)

您已将代理添加到改造对象

java.net.Proxy proxy = new Proxy(Proxy.Type.HTTP,  new InetSocketAddress(proxyHost, proxyPort));
OkHttpClient client = new OkHttpClient.Builder().proxy(proxy).build();

Retrofit.Builder builder = new Retrofit.Builder().client(client);
Retrofit retrofit = builder.build();

答案 1 :(得分:0)

就我而言,我已连接到代理网络,此问题与改造无关。