如何附加XML文件中的HTTP POST请求消息体? [英] How to attach XML file in message body of HTTP post request?

查看:215
本文介绍了如何附加XML文件中的HTTP POST请求消息体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何安装XML文件中的HTTP POST请求消息体?

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

任何一个可以举个例子的那种

can any one give example for that kind

推荐答案

下面是一个简单的code段制作HTTP POST请求所需网址:

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(); 
}

这篇关于如何附加XML文件中的HTTP POST请求消息体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆