我正在尝试访问https soap API ..我从服务器获得证书并添加到JRE cacerts(我可以在密钥库中看到证书)。我正在运行一个独立的类并访问SOAP服务。我收到“401 Authorization Required”错误。我确信凭据是正确的(也验证区分大小写)。
我想知道为什么它会抛出以下异常:
- ERROR:return code: 401
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head> <title>401 Authorization Required</title> </head>
<body> <h1>Authorization Required</h1> <p>This server could not verify that you are authorized to access the document requested. Either you supplied the wrong credentials (e.g., bad password), or your browser doesn't understand how to supply the credentials required.</p>
</body>
</html> return code: 401 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html><head> <title>401 Authorization Required</title> </head>
<body> <h1>Authorization Required</h1> <p>This server could not verify that you are authorized to access the document requested. Either you supplied the wrong credentials (e.g., bad password), or your browser doesn't understand how to supply the credentials required.</p> </body></html>
注意:1)用户名和密码值是字符串。是否需要加密(因为我作为Java应用程序运行客户端)。虽然我试图以webapp(https)运行,但仍会导致相同的异常。 2)我可以通过浏览器(带有用户名和密码)从系统访问SOAP端点,因此我们可以排除任何与网络相关的问题。
// Code snippet
PSPServiceLocator pfspLocator = new PSPServiceLocator();
pfspLocator.setPSPPortEndpointAddress(strNewAddress);
PSPPort pfspPort = pfspLocator.getPSPPort();
PSPBindingStub pfspStub = (PSPBindingStub)pfspPort;
// Force HTTP/1.0
pfspStub._setProperty(
org.apache.axis.MessageContext.HTTP_TRANSPORT_VERSION, org.apache.axis.transport.http.HTTPConstants.HEADER_PROTOCOL_V10);
// Configure Basic or Digest Authentication
pfspStub.setUsername(userName); // string value
pfspStub.setPassword(password); // string value
int timeout = 1000;
pfspStub.setTimeout(timeout);
String strResultXML = pfspPort.cliRun(cmd);