我想通过发送和对象来使用来自 java 的 .asmx SOAP Web 服务。该服务还使用基本身份验证。我已成功将对象编组为 xml 并尝试使用以下方法发送。
我尝试了以下方法来做同样的事情:
URL url = new URL("https://api.sandbox.ewaypayments.com/Soap.asmx?wsdl");
httpURLConnection = (HttpURLConnection) url.openConnection();
httpURLConnection.setRequestProperty("Authorization", "Basic " + encodedString);
httpURLConnection.setRequestMethod("POST");
httpURLConnection.setRequestProperty("Content-Length", String.valueOf(xml.length()));
httpURLConnection.setRequestProperty("Content-Type", "text/xml");
httpURLConnection.setRequestProperty("SoapAction", "");
httpURLConnection.setDoInput(true);
httpURLConnection.setDoOutput(true);
httpURLConnection.setUseCaches(false);
httpURLConnection.setRequestProperty("Content-Type", "text/xml");
PrintWriter pw = new PrintWriter(httpURLConnection.getOutputStream());
pw.write(postParameter);
pw.flush();
BufferedReader br = new BufferedReader(new InputStreamReader(httpURLConnection.getInputStream()));
String line = "";
while ((line = br.readLine()) != null)
{
responseMessage.append(line);
}
Call call = new Call("https://api.sandbox.ewaypayments.com/Soap.asmx");
call.setOperationName(new QName("https://api.sandbox.ewaypayments.com/", "CreateAccessCode"));
call.setSOAPActionURI("https://api.sandbox.ewaypayments.com/CreateAccessCode");
String strResult = (String) call.invoke(new Object[] { new CreateAccessCodeRequest()});
但是我通过上述方法从服务器收到 500 错误。我知道服务器端没有问题,因为 php 调用工作正常。我只是不能让它与java一起工作。请帮忙。