我试图通过代理服务器使用Apache Client 4.5连接到我的service-now实例。不幸的是,连接因以下异常而失败。
HTTP / 1.1 401未经授权 {“error”:{“message”:“用户未经过身份验证”,“详细信息”:“需要提供身份验证信息”},“状态”:“失败”}
我可以理解这是因为身份验证异常,但我似乎确实提供了如下所示的凭据。
代码段:
public void getRequestWithProxy() throws ClientProtocolException, IOException
{
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(
new AuthScope("proxy.xxxx.com", 0000),
new UsernamePasswordCredentials("proxyuser", "proxypassword"));
credsProvider.setCredentials(
new AuthScope("instance.service-now.com", 443),
new UsernamePasswordCredentials("username", "password"));
CloseableHttpClient httpclient = HttpClients.custom()
.setDefaultCredentialsProvider(credsProvider).build();
try {
HttpHost target = new HttpHost("instance.service-now.com", 443, "https");
HttpHost proxy = new HttpHost("proxy.xxxx.com", 0000);
RequestConfig config = RequestConfig.custom()
.setProxy(proxy)
.build();
HttpGet httpget = new HttpGet("/api/now/table/incident");
httpget.setConfig(config);
System.out.println("Executing request " + httpget.getRequestLine() + " to " + target + " via " + proxy);
CloseableHttpResponse response = httpclient.execute(target, httpget);
try {
System.out.println("----------------------------------------");
System.out.println(response.getStatusLine());
System.out.println(EntityUtils.toString(response.getEntity()));
} finally {
response.close();
}
} finally {
httpclient.close();
}
}
我认为我可以访问正在访问的网址,因为在浏览器中尝试使用相同的网址“https://instance.service-now.com/api/now/table/incident”可以正常使用SSO(Single Sing On)。
请帮助我找不到的东西。
先谢谢你的帮助。
谢谢。
答案 0 :(得分:0)
你说这是一个网址。新的AuthScope应该是主机名而不是URL。