相关疑难解决方法(0)

为什么这个简单的SOAP客户端不工作(org.apache.http)?

我想将一个XML文件作为请求发送到SOAP服务器.这是我的代码:( 使用org.apache.http使用SOAP操作发送HTTP Post请求进行了修改)

import org.apache.http.client.*;
import org.apache.http.client.methods.*;
import org.apache.http.impl.client.*;
import org.apache.http.entity.StringEntity;
import org.apache.http.protocol.HTTP;
import org.apache.http.HttpResponse;
import java.net.URI;

public static void req()   {
        try {
            HttpClient httpclient = new DefaultHttpClient();
            String body="xml here";
            String bodyLength=new Integer(body.length()).toString();

            URI uri=new URI("http://1.1.1.1:100/Service");
            HttpPost httpPost = new HttpPost(uri);
            httpPost.setHeader( "SOAPAction", "MonitoringService" );
            httpPost.setHeader("Content-Type", "text/xml;charset=UTF-8");


            StringEntity entity = new StringEntity(body, "text/xml",HTTP.DEFAULT_CONTENT_CHARSET);
            httpPost.setEntity(entity);

            RequestWrapper requestWrapper=new RequestWrapper(httpPost);
            requestWrapper.setMethod("POST");


            requestWrapper.setHeader("Content-Length",bodyLength);
            HttpResponse response = httpclient.execute(requestWrapper);
            System.out.println(response);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
Run Code Online (Sandbox Code Playgroud)

在此之前我从服务器收到错误'http 500'(内部服务器错误),但现在我没有得到任何回复.我知道服务器工作正常,因为与其他客户端没有问题.

谢谢.

java post soap http apache-commons-httpclient

4
推荐指数
1
解决办法
6885
查看次数

标签 统计

apache-commons-httpclient ×1

http ×1

java ×1

post ×1

soap ×1