在 Android 上使用 HTTP POST XML

发布于 2024-11-25 00:44:44 字数 1456 浏览 1 评论 0原文

我正在尝试在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

和影子一齐双人舞 2024-12-02 00:44:44

尝试应用程序/json。在 Android 2 上,某些型号的 xml 响应出现问题

Try application/json. On Android 2 something wrong with xml responses on some models

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文