62,614
社区成员
发帖
与我相关
我的任务
分享
HttpURLConnection connection = null;
String soapAction = "userInfoSynSV";
String requestXML = getXML();
String serviceURL = "--------";
connection = openConnection(serviceURL, requestXML, soapAction);
InputStream input = connection.getInputStream();
StringBuffer buf = new StringBuffer();
byte[] b = new byte[1024];
int length = -1;
while ((length = input.read(b)) != -1) {
buf.append(new String(b, 0, length, "UTF-8"));
}
return buf.toString();
private static HttpURLConnection openConnection(String serviceURL,
String requestXML, String soapAction) throws Exception {
URL url = new URL(serviceURL);
URLConnection connection = url.openConnection();
String host =url.getHost();
HttpURLConnection httpConn = (HttpURLConnection) connection; // Open the
httpConn.setRequestProperty("Host", host);
httpConn.setRequestProperty("Content-Length", requestXML.length() + "");
httpConn.setRequestProperty("Content-Type", "application/soap+xml; charset=utf-8");
// httpConn.setRequestProperty("Content-Type", "text/xml; charset=utf-8");
httpConn.setRequestProperty("SOAPAction", soapAction);
httpConn.setRequestMethod("POST");
httpConn.setDoOutput(true);
httpConn.setDoInput(true); // Everything's set up; send the XML that was
OutputStream os = httpConn.getOutputStream();
os.write(requestXML.getBytes("utf-8"));
os.flush();
os.close();
return httpConn;
}