📄 soapclient.java
字号:
/*
* Created on 2004-8-11
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
package com.gctech.misc.util;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.ProtocolException;
import java.net.URL;
import java.net.URLConnection;
/**
* SOAPClient4XG. Read the SOAP envelope file passed as the second
* parameter, pass it to the SOAP endpoint passed as the first parameter, and
* print out the SOAP envelope passed as a response. with help from Michael
* Brennan 03/09/01
*
*
* @author Bob DuCharme
* @version 1.1
* @param SOAPUrl URL of SOAP Endpoint to send request.
* @param xmlFile2Send A file with an XML document of the request.
*
* 5/23/01 revision: SOAPAction added
*/
public class SOAPClient {
public static String provision(String SOAPUrl,String xmlFile2Send,String SOAPAction) throws MalformedURLException, IOException, FileNotFoundException, ProtocolException {
// Create the connection where we're going to send the file.
URL url = new URL(SOAPUrl);
URLConnection connection = url.openConnection();
HttpURLConnection httpConn = (HttpURLConnection) connection;
byte[] b = xmlFile2Send.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);
// Everything's set up; send the XML that was read in to b.
OutputStream out = httpConn.getOutputStream();
System.out.println("request:"+new String(b));
out.write(b);
out.close();
// Read the response and write it to standard out.
InputStreamReader isr = new InputStreamReader(httpConn.getInputStream());
String returnStr = IOUtility.toString(isr);
httpConn.disconnect();
System.out.print("response:"+returnStr);
return returnStr;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -