1
我要访问一个Web服务,这是代码的样子:javax.xml.ws.Service在构造函数中失败,因为网站拥有用户名/密码
URL url = new URL("http://localhost:8080/sample?ver_=1.0");
QName qname = new QName("http://webservices.sample.com/sample", "sample");
javax.xml.ws.Service service = javax.xml.ws.Service.create(url, qname);
初始化“服务”投行401未经授权的例外。
如果我使用的浏览器访问
http://localhost:8080/sample?ver_=1.0
,一个窗口,询问用户名和密码弹出。
我试图使用Wireshark捕获数据包,并注意到服务的构造函数发送一个HTTP Get到IP地址但没有凭据。
如何确保服务构造函数对HTTP Get的调用包含用户名/密码?
我已经试图把这个电话之前,但它并没有帮助
Authenticator.setDefault(new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(
"username",
"password".toCharArray());
}
});
谢谢!
是使用基本身份验证服务器?数据包中的认证头是什么? –
是的,它的基本认证。这在标题上:Authorization:Basic –
racumin