我尝试通过代理服务器使用Apache Client 4.5连接到我的服务-now实例。不幸的是,连接失败,出现以下异常。
HTTP/1.1 401 Unauthorized {“error”:{“message”:“用户未通过身份验证”,“detail”:“需要提供身份验证信息”},“status”:“失败”}
我可以理解这是因为身份验证异常,但我似乎确实提供了如下所示的凭据。
代码片段:
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 (单点登录)可以很好地工作。
请帮我补上我遗漏的东西。
提前感谢你在这方面的帮助。
谢谢。
发布于 2016-03-29 10:30:34
你说那是个网址。新的AuthScope应该是主机名,而不是URL。
https://stackoverflow.com/questions/36269804
复制相似问题