HTTP响应代码:进行SOAP调用时为400

时间:2019-05-24 16:30:37

标签: java soap httpurlconnection soap-client

我们正在使用HttpURLConnection对象进行SOAP调用。为了进行测试,我使用了以下wsdl,可以使用SoapUI-轻松访问 http://www.dneonline.com/calculator.asmx 我在测试代码中使用添加操作。我使用了与SoapUI中使用的请求相同的请求,该请求成功返回了响应,但是当我使用下面的代码时,我得到了代表错误请求的响应代码400。当我调试时,它表明安全管理器正在重新运行null,这将在代码中进一步检查,然后引发异常。有人可以告诉我如何解决此问题吗?

String responseString = "";
    String outputString = "";
    String wsURL = this.wsURL;
    URL url = new URL(wsURL);
    URLConnection connection = url.openConnection();
    HttpURLConnection httpConn = (HttpURLConnection)connection;
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    String xmlInput =this.wsURL;

    byte[] buffer = new byte[xmlInput.length()];
    buffer = xmlInput.getBytes();
    bout.write(buffer);
    byte[] b = bout.toByteArray();
    // Set the appropriate HTTP parameters.
    //httpConn.setRequestProperty("Name","CalculatorSoap");
    //httpConn.setRequestProperty("SOAP Version","SOAP 1.1");
    httpConn.setRequestProperty("Content-Length",String.valueOf(b.length));
    httpConn.setRequestProperty("Content-Type", "text/xml; charset=utf-8");
    httpConn.setRequestProperty("SOAPAction", "http://tempuri.org/Add");
    httpConn.setRequestMethod("GET");
    httpConn.setDoOutput(true);
    httpConn.setDoInput(true);
    //System.out.println("Error="+httpConn.getErrorStream().toString());
    OutputStream out = httpConn.getOutputStream();

0 个答案:

没有答案