简体   繁体   中英

How to attach XML file in message body of HTTP post request?

How to attach XML file in message body of HTTP post request?

can any one give example for that kind

Here is a sample code snippet for making HTTP POST request on the desired URL:

try { 

String myXML = "<? xml version=1.0> <Request> <Elemtnt> <data id=\"1\">E1203</data> <data id=\"2\">E1204</data> </Element> </Request>";

HttpClient httpClient = new DefaultHttpClient(); 
HttpContext localContext = new BasicHttpContext(); 
HttpPost httpPost = new HttpPost("https://www.google.com/calendar/feeds/default/owncalendars/full"); 

List<NameValuePair> dataToPost = new ArrayList<NameValuePair>(); 

dataToPost.add(new BasicNameValuePair("yourxml", myXML)); 

httpPost.setEntity(new UrlEncodedFormEntity(dataToPost)); 

HttpResponse response = httpClient.execute(httpPost, localContext); 

} catch (Exception e) { 
e.printStackTrace(); 
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM