无法通过应用程序访问代理,但能够使用Linux命令

时间:2019-10-02 10:31:55

标签: java apache proxy apache-httpclient-4.x credentials

美好的一天,

有一个代理服务器,我能够使用命令访问它并获取响应代码200。以下是我的Linux终端的输出:

$ export http_proxy="http://user1:Pass0x40m@172.21.14.58:8080/"
$ curl -I http://www.google.com
HTTP/1.1 200 OK

以下是我在应用程序中使用代理调用的Java代码:

    Credentials credentials = new UsernamePasswordCredentials("user1","Pass0x40m");
    AuthScope authScope = new AuthScope("172.21.14.58", 8080);
    CredentialsProvider credsProvider = new BasicCredentialsProvider();
    credsProvider.setCredentials(authScope, credentials);

    CloseableHttpClient client = HttpClientBuilder.create().useSystemProperties().setDefaultCredentialsProvider(credsProvider).build();
    response = client.execute(post);

但是,我一直遇到以下错误:

Access Denied (authentication_failed)
Your credentials could not be authenticated: "General authentication failure due to bad user ID or authentication token.". You will not be permitted access until your credentials can be verified.
This is typically caused by an incorrect username and/or password, but could also be caused by network problems.
For assistance, contact your network support team.

即使我将密码设置为原始密码,也是如此:

Credentials credentials = new UsernamePasswordCredentials("user1","Pass@m");

有人知道我应该进一步寻找哪一点吗?

仅供参考,我正在使用apache httpclient 4.5.2

0 个答案:

没有答案