【问题标题】:How to Send Xml Data In HttpPost in Android如何在 Android 的 HttpPost 中发送 Xml 数据
【发布时间】:2014-12-09 14:33:24
【问题描述】:

我知道这是一个重复的问题。但我没有得到正确的答案。我的问题是这样的。我有一些数据,我想将这些数据转换为 xml,我想用 HttpPost 请求发送这个 xml。当执行此 Post 请求时,它会为我提供 xml 格式的数据。然后我想解析xml数据。请告诉我最好的方法。我已经阅读了一些教程,但我没有得到正确的答案。有没有其他方法可以将对象值转换为 xml 记帐到类字段像 java 中的编组和解组请告诉我答案。提前致谢。我已经阅读了一些示例,这里有一些链接。 click herehere

【问题讨论】:

标签: android xml


【解决方案1】:

使用 HTTP POST 的 XML 解析器的简单示例,

 HttpClient httpclient = new DefaultHttpClient();
 HttpPost httppost = new HttpPost("http://192.168.192.131/");

try {
StringEntity se = new StringEntity( "<aaaLogin inName=\"admin\" inPassword=\"admin123\"/>", HTTP.UTF_8);
se.setContentType("text/xml");
httppost.setEntity(se);

HttpResponse httpresponse = httpclient.execute(httppost);
HttpEntity resEntity = httpresponse.getEntity();
tvData.setText(EntityUtils.toString(resEntity));        
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace(); 
}

【讨论】:

  • 我怀疑如果我需要再添加一个标签,那么我必须将该标签附加到 "" 吗?有没有其他方法可以将对象值转换为 xml 记帐到类字段,如 java 中的编组和解组
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-06-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多