我正在尝试访问 https 肥皂 API。我有来自服务器的证书并添加到 JRE cacerts(我可以在密钥库中看到证书)。我正在运行一个独立的类并访问 SOAP 服务。我收到“需要 401 授权”错误。我确定凭据是正确的(也已验证区分大小写)。
我想知道为什么它在下面抛出异常:
- 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);