Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/345.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/rest/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用域(+;用户名+;密码)身份验证在Java中调用REST服务url_Java_Rest_Web Services_Jersey Client - Fatal编程技术网

使用域(+;用户名+;密码)身份验证在Java中调用REST服务url

使用域(+;用户名+;密码)身份验证在Java中调用REST服务url,java,rest,web-services,jersey-client,Java,Rest,Web Services,Jersey Client,我正在尝试从REST服务URL获取响应, 螺母获取错误: 401:用户名或密码无效 我能够在浏览器中点击此URL,并使用提供的凭据获得响应, 以及在SoapUI工具中。 在从SoapUI点击URL时,我在身份验证部分提供域值,如果没有该URL,我将得到身份验证错误 但是从java我无法得到响应 如果有人能帮忙的话 公共类测试{ public static void main(String[] args) { System.setProperty("https.protocols", "

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

我能够在浏览器中点击此URL,并使用提供的凭据获得响应, 以及在SoapUI工具中。 在从SoapUI点击URL时,我在身份验证部分提供域值,如果没有该URL,我将得到身份验证错误

但是从java我无法得到响应

如果有人能帮忙的话

公共类测试{

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。

Hi vikram,

  check your username it may be wrong like myuser

尝试在没有代理的情况下建立连接。如果直接连接起作用,代理可能会弄乱您的身份验证请求。是的,在没有代理的情况下也尝试了,仍然是相同的错误。我想这与域值有关,如果有一种方法可以将域值传递给身份验证,它可能会起作用,我也在尝试同样的方法,请告诉我是否有您知道的任何事情。我用id/密码尝试了很多次,这不是问题,我很确定。