平平庸庸
java soap 客户类
上一篇 /
下一篇 2009-05-13 16:55:18
/ 个人分类:测试工具
import java.io.*;
import java.net.*;
public class DoRequest {
public String sendSoap(String soapurl,String soapPack) throws Exception {
URL url = new URL(soapurl);
URLConnection connection = url.openConnection();
HttpURLConnection httpConn = (HttpURLConnection) connection;
byte[] b=soapPack.getBytes();
// Set the appropriate HTTP parameters.
httpConn.setRequestProperty( "Content-Length",String.valueOf( b.length ) );
httpConn.setRequestProperty("Content-Type","text/xml; charset=utf-8");
httpConn.setRequestProperty("SOAPAction",SOAPAction);
httpConn.setRequestMethod( "POST" );
httpConn.setDoOutput(true);
httpConn.setDoInput(true);
OutputStream ut = httpConn.getOutputStream();
out.write( b );
out.close();
// Read the response and write it to response.
try{
InputStreamReader isr =new InputStreamReader(httpConn.getInputStream());
BufferedReader in = new BufferedReader(isr);
String inputLine;
String soapresponse="";
while ((inputLine = in.readLine()) != null)
soapresponse=soapresponse+inputLine;
in.close();
return soapresponse;
}catch(Exception e){
InputStreamReader isr=new InputStreamReader(httpConn.getErrorStream());
BufferedReader in = new BufferedReader(isr);
String inputLine;
String soapresponse="";
while ((inputLine = in.readLine()) != null)
soapresponse=soapresponse+inputLine;
in.close();
return soapresponse;
}
}
}
收藏
举报
TAG: