cuốn sách gpt4 ai đã làm

java - SOAP 授权

In lại Tác giả: Walker 123 更新时间:2023-11-29 03:31:40 26 4
mua khóa gpt4 Nike

我的 soap 连接代码:

MessageFactory msgFactory = MessageFactory.newInstance();  
SOAPMessage message = msgFactory.createMessage();
String loginPassword = "user:password";
message.getMimeHeaders().addHeader("Authorization", "Basic " + Base64.encode(loginPassword.getBytes()).toString());
SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
SOAPConnection soapConnection = soapConnectionFactory.createConnection();

// Send SOAP Message to SOAP Server
String url = "http://servername/name1";
SOAPMessage soapResponse = soapConnection.call(message, url);

我总是遇到异常:

CAUSE:

com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: Bad response: (401Unauthorized

怎么了?

请求:

        String soapText =  
""
+""
+""
+""
+""
+"54321"
+"2013-07-26"
+"2013-07-27"
+"12:00"
+"1"
+"Леся"
+"B"
+"3032"
+"138"
+"54321"
+""
+""
+"1"
+"29"
+"<сount>10"
+"Банан"
+"37268"
+"
"
+"
"
+"
"
+"
"
+"
"
+"
";

SOAPPart soapPart = message.getSOAPPart();

// Load the SOAP text into a stream source
byte[] buffer = soapText.getBytes();
ByteArrayInputStream stream = new ByteArrayInputStream(buffer);
StreamSource source = new StreamSource(stream);

// Set contents of message
soapPart.setContent(source);

câu trả lời hay nhất

您需要将代码更改为这样-

   MessageFactory msgFactory = MessageFactory.newInstance();  
SOAPMessage message = msgFactory.createMessage();
String loginPassword = "user:password";
message.getMimeHeaders().addHeader("Authorization", "Basic " + new String(Base64.encode(loginPassword.getBytes())));
SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
SOAPConnection soapConnection = soapConnectionFactory.createConnection();

// Send SOAP Message to SOAP Server
String url = "http://servername/name1";
SOAPMessage soapResponse = soapConnection.call(message, url);

这将解决您的问题。

关于java - SOAP 授权,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17881841/

26 4 0
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress