Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. void post(String strURL, String strSoapAction, String strXMLFilename) throws Exception{
  2.  
  3. File input = new File(strXMLFilename);
  4. PostMethod post = new PostMethod(strURL);
  5. RequestEntity entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1");
  6. post.setRequestEntity(entity);
  7. post.setRequestHeader("SOAPAction", strSoapAction);
  8. HttpClient httpclient = new HttpClient();
  9. try {
  10. int result = httpclient.executeMethod(post);
  11. System.out.println("Response status code: " + result);
  12. System.out.println("Response body: ");
  13. System.out.println(post.getResponseBodyAsString());
  14. } finally {
  15. post.releaseConnection();
  16. }
  17. }
  18.  
  19. void sendRequest()throws Exception {
  20. System.out.println("Start sending " + action + " request");
  21. URL url = new URL( serviceURL );
  22. HttpURLConnection rc = (HttpURLConnection)url.openConnection();
  23. //System.out.println("Connection opened " + rc );
  24. rc.setRequestMethod("POST");
  25. rc.setDoOutput( true );
  26. rc.setDoInput( true );
  27. rc.setRequestProperty( "Content-Type", "text/xml; charset=utf-8" );
  28. String reqStr = reqT.getRequest();
  29. int len = reqStr.length();
  30. rc.setRequestProperty( "Content-Length", Integer.toString( len ) );
  31. rc.setRequestProperty("SOAPAction", soapActions[actionLookup(action)] );
  32. rc.connect();
  33. OutputStreamWriter out = new OutputStreamWriter( rc.getOutputStream() );
  34. out.write( reqStr, 0, len );
  35. out.flush();
  36. System.out.println("Request sent, reading response ");
  37. InputStreamReader read = new InputStreamReader( rc.getInputStream() );
  38. StringBuilder sb = new StringBuilder();
  39. int ch = read.read();
  40. while( ch != -1 ){
  41. sb.append((char)ch);
  42. ch = read.read();
  43. }
  44. response = sb.toString();
  45. read.close();
  46. rc.disconnect();
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement