在 Android 上使用 HTTP POST XML
我正在尝试在 android 上发布 xml。相同的 xml 和服务器在 iphone 上完美运行,但在 android 上我收到无效 xml 错误消息。
public void postData() {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://stage.isadiasjd.com.tr/asdasdad-web/getProductDeviceService.do");
try {
StringEntity se = new StringEntity("<customer><districtId>2541</districtId><barcode>45464654654917</barcode><udid>dade51ce2c127310d1df5ee25e876e46feae470b</udid><email>[email protected]</email><hashCode>2500a7005c01903093fa268984zczczczaeawdwa2w1d3w6dec9b61afbe28f37baad819ba3e0d</hashCode></customer>", "UTF-8");
// se.setContentType("text/xml");
se.setContentType("application/atom+xml");
httppost.setEntity(se);
HttpResponse httpresponse = httpclient.execute(httppost);
HttpEntity resEntity = httpresponse.getEntity();
String ss = EntityUtils.toString(resEntity);
Log.v("http req", ss);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
Log.v("ex","1");
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
Log.v("ex","2");
e.printStackTrace();
}
}
I am trying to post xml on android. Same xml and server works on iphone perfectly, but on android i am getting invalid xml error message.
public void postData() {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://stage.isadiasjd.com.tr/asdasdad-web/getProductDeviceService.do");
try {
StringEntity se = new StringEntity("<customer><districtId>2541</districtId><barcode>45464654654917</barcode><udid>dade51ce2c127310d1df5ee25e876e46feae470b</udid><email>[email protected]</email><hashCode>2500a7005c01903093fa268984zczczczaeawdwa2w1d3w6dec9b61afbe28f37baad819ba3e0d</hashCode></customer>", "UTF-8");
// se.setContentType("text/xml");
se.setContentType("application/atom+xml");
httppost.setEntity(se);
HttpResponse httpresponse = httpclient.execute(httppost);
HttpEntity resEntity = httpresponse.getEntity();
String ss = EntityUtils.toString(resEntity);
Log.v("http req", ss);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
Log.v("ex","1");
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
Log.v("ex","2");
e.printStackTrace();
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试应用程序/json。在 Android 2 上,某些型号的 xml 响应出现问题
Try application/json. On Android 2 something wrong with xml responses on some models