how to send xml request to restful webservice in java
how to send xml request to restful webservice in java
Want to know how to send xml request to restful webservice in java? we have a huge selection of how to send xml request to restful webservice in java information on alibabacloud.com
Java send mail, the main use of the jar
The jar package used
Mail.jar
Xfire for Web Service
General ideas and steps
1. Define Mail Delivery interface
2. Configure the mail thread pool
3. Record Log
Entity Mailbean
The code is as follows
Copy Code
Package Com.reagle.bean;Import Java.util.Date;Import java.util.List;Import java.util.Properties;Import Javax.activation.Data
Java method for accessing XML data returned by WebService
This example describes how Java accesses WebService to return XML data. Share it with you for your reference. The details are as follows:
?
1 2 3 4 5 6 7 8 9 1
WebService debugging Tools mentioned earlier, if you are interested in writing test code, it is very good ah.
I also think so, there are ideas may wish to try Oh. Then, my program mainly uses the HttpURLConnection class, first splicing conforms to the SOAP protocol XML string information, then establishes the connection with the WebService server, sends the HTTP
The example in this article describes the way Java accesses WebService return XML data. Share to everyone for your reference. as follows:
Import java.io.IOException;
Import Java.io.InputStream;
Import java.net.MalformedURLException;
Import Java.net.URL;
Import java.net.URLConnection;
Import java.io.FileNotFoundException;
Import Java.io.FileOutputStream;
Imp
-Conn.setrequestproperty ("Accept", "*/*"); theConn.setrequestproperty ("Connection", "keep-alive"); theConn.setrequestproperty ("User-agent", the"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ");94 //to send a POST request, you must set the following two lines theConn.setdooutput (true); theConn.setdoinput (true); the //gets the output stream corresponding to the URLConne
= "";try {URL realurl = new URL (URL);Opening and linking between URLsURLConnection conn = Realurl.openconnection ();To set common request propertiesConn.setrequestproperty ("Accept", "*/*");Conn.setrequestproperty ("Connection", "keep-alive");Conn.setrequestproperty ("User-agent","Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ");To send a POST request
There are some support for stateless protocol requests (HTTP) in the JDK, and I'll describe a small example (component) I wrote:
Let's first build a request Class (Httprequester).
This class encapsulates the JAVA implementation code for a simple request, as follows:
Import Java.io.BufferedReader;
Import java.io.IOException;
Import Java.io.InputStream;
Import
processing"); in the}Else { the AboutSYSTEM.OUT.PRINTLN ("Request Server failed"); the the } the + -}Catch(Exception e) { theSYSTEM.OUT.PRINTLN ("Request Exception");Bayi Throw NewRuntimeException (e); the } the - returnresult; - } the the}Test receive1 @ Page Language="
Java's httpclient and okhttp request network, are more troublesome than the requests of PY, also more than the self-brought package of Py urllib trouble. Now think of requests is really for humans, take to use, basic no special case without two times package.Java or to be encapsulated into a get post tool class is useful, the tool class is a static method of the class, more general, no need to new object. As with the @staticmethod method of py. Packag
Here are two ways to send URL requests using Java and get the values returned by the serverThe first method:
Copy Code code as follows:
Import org.apache.http.HttpEntity;
Import Org.apache.http.HttpResponse;
Import Org.apache.http.NameValuePair;
Import org.apache.http.client.HttpClient;
Import org.apache.http.client.entity.UrlEncodedFormEntity;
Import Org.apache.http.client.methods.HttpPost;
In java, scoket is used to simulate an http post request to send images or files.
Recently, I encountered a problem where two systems shared the user's profile picture and saved it in one system. This involved sending the picture to another system through scoket for storage, the initial thought was to read the image into a byte [] array and then
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.