使用HTTP在Android上POST XML

时间:2011-07-20 14:14:03

标签: java android http httpclient http-post

我想在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>Xzcxzcxzczxc@zxczxcxczxc.com</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();
    }
} 

1 个答案:

答案 0 :(得分:0)

尝试application / json。在Android 2上,某些型号的xml响应有问题