[英]Call REST service url in Java with DOMAIN(+ username+password) Authentication
我正在尝试从 REST 服务 URL 获得响应,螺母出现错误:401:用户名或密码无效。
我可以在浏览器中点击这个 URL 并使用提供的凭据以及在 SoapUI 工具中获得响应。 我在从 SoapUI 访问 URL 时在身份验证部分提供域值,否则我会收到身份验证错误。
但是从 java 我无法得到响应。
如果有人可以请帮助
公共 class Test_Rest_WS {
public static void main(String[] args) {
System.setProperty("https.protocols", "TLSv1.2");
System.setProperty("http.proxyHost","omaproxy.1dc.com");
System.setProperty("http.proxyPort", "8080");
ClientConfig clientConfig = new DefaultClientConfig();
//clientConfig.getFeatures().put( JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
Client client = Client.create(clientConfig);
final HTTPBasicAuthFilter authFilter = new HTTPBasicAuthFilter("mysuer", "mypassword");
client.addFilter(authFilter);
client.addFilter(new LoggingFilter());
WebResource webResource = client
.resource("https://myurl");
ClientResponse resp = webResource.accept("application/json")
.type("application/json").get(ClientResponse.class);
if(resp.getStatus() != 200){
System.err.println("Unable to connect to the server");
}
String output = resp.getEntity(String.class);
System.out.println("response: "+output);
}
}
使用上述代码出现此错误:401:用户名或密码无效
预期 output:响应 xml。
嗨维克拉姆,
check your username it may be wrong like myuser
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.