1

甚至可能吗?文档没有说清楚。我尝试了各种不同的机制来使身份验证正常工作,但我不断收到“401:未经授权”错误。这是我所在的位置:

    stub = new EngineStub();

    HttpClient client = new HttpClient();
    client.getParams().setAuthenticationPreemptive(true);
    stub._getServiceClient().getServiceContext().getConfigurationContext().setProperty(HTTPConstants.CACHED_HTTP_CLIENT, client);

    HttpTransportProperties.Authenticator auth = new HttpTransportProperties.Authenticator();
    List<String> authpref = new ArrayList<String>();
    authpref.add(AuthPolicy.BASIC);
    auth.setAuthSchemes(authpref);
    auth.setUsername(username); 
    auth.setPassword(password);
    auth.setPreemptiveAuthentication(true);
    stub._getServiceClient().getOptions().setProperty(HTTPConstants.AUTHENTICATE, auth);
4

1 回答 1

3

你是什​​么意思axis2与BASIC AUTH一起工作?如果您的后端服务使用基本身份验证进行保护,您所要做的就是从客户端设置基本身份验证标头并发送请求。您的客户端代码看起来不错;不确定身份验证政策;尝试不这样;

 auth.setUsername(USER_NAME);
    auth.setPassword(PASSWORD);
    auth.setPreemptiveAuthentication(true);
    option.setProperty(org.apache.axis2.transport.http.HTTPConstants.AUTHENTICATE, auth);
    option.setManageSession(true);
于 2013-03-13T12:33:34.277 回答