使用DOMAIN(+用户名+密码)身份验证以Java调用REST服务的URL

问题描述 投票:0回答:1

我正在尝试从REST服务URL获取响应,螺母变错误:401:无效的用户名或密码。

我能够在浏览器中点击此URL,并使用提供的凭据获得回复,以及在SoapUI工具中。当我从SoapUI中访问URL时,我在“身份验证”部分中提供了“域”值,否则我将收到身份验证错误。

但是从Java我无法获得响应。

如果有人可以请帮助

公共类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:无效的用户名或密码

预期输出:响应xml。

java rest web-services jersey-client
1个回答
0
投票

Hi vikram,

  check your username it may be wrong like myuser
© www.soinside.com 2019 - 2024. All rights reserved.