How to do Basic Authentication with an Axis2 ADB Client?

白昼怎懂夜的黑 提交于 2019-12-05 14:54:16

问题


I'm trying to figure out how to do Basic Authentication with an ADB Axis2 version 1.5 Client.

I'm trying the following:

HttpTransportProperties.Authenticator basicAuth = new HttpTransportProperties.Authenticator();
basicAuth.setUsername(username);
basicAuth.setPassword(password);
final Options clientOptions = serviceStub._getServiceClient().getOptions();
clientOptions.setProperty(HTTPConstants.AUTHENTICATE, basicAuth);

However this does not work and the needed line in the message header is not being added.


回答1:


Got the answer from the following site:

http://www.inpc.de/blog/2007/05/axis2-12-basic-authentication.html

Apparently I was missing:

basicAuth.setPreemptiveAuthentication(true);



回答2:


I think you're close, your code looks really close to this? The following is the difference:

clientOptions.setProperty(
   org.apache.axis2.transport.http.HTTPConstants.BASIC_AUTHENTICATION,
                basicAuth);


来源:https://stackoverflow.com/questions/1528089/how-to-do-basic-authentication-with-an-axis2-adb-client

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!