接近1个堆栈跟踪
javax.xml.ws.WebServiceException:无法访问位于的WSDL。它失败了: 服务器返回URL:http://username:password@10.XXX.15.XX/ClientExt/NewAPI/api.asmx?wsdl的HTTP响应代码:401。 在com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.tryWithMex(RuntimeWSDLParser.java:250) 在com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.parse(RuntimeWSDLParser.java:231) 在com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.parse(RuntimeWSDLParser.java:194) 在com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.parse(RuntimeWSDLParser.java:163) 在com.sun.xml.internal.ws.client.WSServiceDelegate.parseWSDL(WSServiceDelegate.java:348) 在com.sun.xml.internal.ws.client.WSServiceDelegate。(WSServiceDelegate.java:306) 在com.sun.xml.internal.ws.client.WSServiceDelegate。(WSServiceDelegate.java:215) 在com.sun.xml.internal.ws.client.WSServiceDelegate。(WSServiceDelegate.java:196) 在com.sun.xml.internal.ws.client.WSServiceDelegate。(WSServiceDelegate.java:192) 在com.sun.xml.internal.ws.spi.ProviderImpl.createServiceDelegate(ProviderImpl.java:104) 在javax.xml.ws.Service。(Service.java:77) 在org.tempuri.Api(Api.java:82)
方法1:
Authenticator.setDefault(new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password.toCharArray());
}
});
方法2
HttpURLConnection myURLConnection = (HttpURLConnection)url.openConnection();
String userCredentials = "username:password";
String basicAuth = "Basic " + new String(new Base64().encode(userCredentials.getBytes()));
myURLConnection.setRequestProperty ("Authorization", basicAuth);
myURLConnection.setRequestMethod("GET");
myURLConnection.setDoInput(true);
myURLConnection.setConnectTimeout(1500000);
myURLConnection.connect();
int responseCode = myURLConnection.getResponseCode();//returns 200 and error
我在方法2中得到响应代码200,也超过了stacktrace作为错误消息。
然后,我尝试使用Authenticator(方法1),如果我调用javaTester文件,但通过应用程序调用时出现以下错误消息,则可以正常工作。
org.apache.axis2.AxisFault:HTTP(401)未经授权的地址:http://username:password@10.XXX.15.XX/ClientExt/NewAPI/api.asmx?wsdl