Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void post(String strURL, String strSoapAction, String strXMLFilename) throws Exception{
- File input = new File(strXMLFilename);
- PostMethod post = new PostMethod(strURL);
- RequestEntity entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1");
- post.setRequestEntity(entity);
- post.setRequestHeader("SOAPAction", strSoapAction);
- HttpClient httpclient = new HttpClient();
- try {
- int result = httpclient.executeMethod(post);
- System.out.println("Response status code: " + result);
- System.out.println("Response body: ");
- System.out.println(post.getResponseBodyAsString());
- } finally {
- post.releaseConnection();
- }
- }
- void sendRequest()throws Exception {
- System.out.println("Start sending " + action + " request");
- URL url = new URL( serviceURL );
- HttpURLConnection rc = (HttpURLConnection)url.openConnection();
- //System.out.println("Connection opened " + rc );
- rc.setRequestMethod("POST");
- rc.setDoOutput( true );
- rc.setDoInput( true );
- rc.setRequestProperty( "Content-Type", "text/xml; charset=utf-8" );
- String reqStr = reqT.getRequest();
- int len = reqStr.length();
- rc.setRequestProperty( "Content-Length", Integer.toString( len ) );
- rc.setRequestProperty("SOAPAction", soapActions[actionLookup(action)] );
- rc.connect();
- OutputStreamWriter out = new OutputStreamWriter( rc.getOutputStream() );
- out.write( reqStr, 0, len );
- out.flush();
- System.out.println("Request sent, reading response ");
- InputStreamReader read = new InputStreamReader( rc.getInputStream() );
- StringBuilder sb = new StringBuilder();
- int ch = read.read();
- while( ch != -1 ){
- sb.append((char)ch);
- ch = read.read();
- }
- response = sb.toString();
- read.close();
- rc.disconnect();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement