Can't do a HTTP Post to a Web Service from my Android App

六眼飞鱼酱① 提交于 2019-12-08 06:18:25

in your second piece of code add ::

   // Execute HTTP Post Request  
    UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(postParameters, HTTP.UTF_8);
    httppost.setEntity(formEntity);
    HttpResponse response = httpclient.execute(httppost);   

This is a bit old, but was having a similar issue myself. The first example is the route I went; and the problem with the original example was this line httppost.setHeader("jsonString", jsonObject.toString());. It's adding a Request Header which the server can't parse.

Additionally the declaration of nameValuePairs is unnecessary.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!