我想送一個XML文件作爲SOAP服務器的請求。 這裏是我的代碼:從服務器(從Sending HTTP Post request with SOAP action using org.apache.http修改)爲什麼這個簡單的SOAP客戶端無法正常工作(org.apache.http)?
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();
}
}
在此之前,我得到錯誤「HTTP 500」(內部服務器錯誤),但我現在沒有得到任何答覆的。我知道服務器正常工作,因爲與其他客戶端沒有問題。
謝謝。
*「before」*是什麼意思?如果你發送一個有效的xml字符串而不是'xml here'會發生什麼? – brimborium
請指定您是否使用IDE,如果是,那麼哪個。如果您使用的是Oracle Jdeveloper 11g等IDE,則只需導入WSDL,IDE將自動生成代碼。 –
您應該發佈請求的正文。如果你的xml有問題,你可能不會得到任何迴應。 – Err