如何从JAVA调用SOAP web服务
我想知道我们如何从java程序的GET和POST请求中调用SOAP web服务。用谷歌搜索您自己的标题并查找类似jax ws的内容(例如)(你可以先做一些研究。抱歉,在这里问这么广泛的问题…不算。欢迎来到堆栈溢出。很抱歉,但是你的问题不符合堆栈溢出格式。请务必签出。你确定这是SOAP吗?如何从JAVA调用SOAP web服务,java,web-services,Java,Web Services,我想知道我们如何从java程序的GET和POST请求中调用SOAP web服务。用谷歌搜索您自己的标题并查找类似jax ws的内容(例如)(你可以先做一些研究。抱歉,在这里问这么广泛的问题…不算。欢迎来到堆栈溢出。很抱歉,但是你的问题不符合堆栈溢出格式。请务必签出。你确定这是SOAP吗? import java.io.BufferedReader; import java.io.DataOutputStream; import java.io.InputStreamReader; import
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import javax.net.ssl.HttpsURLConnection;
public class HttpURLConnectionExample{
private final String USER_AGENT = "Mozilla/5.0";
public static void main(String[] args) throws Exception {
HttpURLConnectionExample http = new HttpURLConnectionExample();
//System.out.println("Testing 1 - Send Http GET request");
//http.sendGet();
System.out.println("\nTesting 2 - Send Http POST request");
http.sendPost();
}
// HTTP GET request
private void sendGet() throws Exception {
String url = "http://http://localhost/getmiweb/public/api/v1/OrderAPI";
URL obj = new URL(url);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
// optional default is GET
con.setRequestMethod("GET");
//add request header
con.setRequestProperty("User-Agent", USER_AGENT);
int responseCode = con.getResponseCode();
System.out.println("\nSending 'GET' request to URL : " + url);
System.out.println("Response Code : " + responseCode);
BufferedReader in = new BufferedReader(
new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
//print result
System.out.println(response.toString());
}
// HTTP POST request
private void sendPost() throws Exception {
String url = "http://http://localhost/getmiweb/public/api/v1/OrderAPI";
URL obj = new URL(url);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
//add reuqest header
con.setRequestMethod("POST");
con.setRequestProperty("User-Agent", USER_AGENT);
con.setRequestProperty("Accept-Language", "en-US,en;q=0.5");
//Passing Parameters
String urlParameters = "token=t0ocgQ/jj8YbjasuLYJ12KJoZmaLNt4zUcEZZKxCU6E=&orderId=12345";
// Send post request
con.setDoOutput(true);
DataOutputStream wr = new DataOutputStream(con.getOutputStream());
wr.writeBytes(urlParameters);
wr.flush();
wr.close();
int responseCode = con.getResponseCode();
System.out.println("\nSending 'POST' request to URL : " + url);
System.out.println("Post parameters : " + urlParameters);
System.out.println("Response Code : " + responseCode);
BufferedReader in = new BufferedReader(
new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
//print result
System.out.println(response.toString());
}
}