android–Http Put Request

android–Http Put Request,第1张

概述我正在使用HttpPut与Android中的服务器通信,我得到的响应代码是500.在与服务器人交谈后,他说准备下面的字符串并发送.{“键”:“值”,“关键”:“值”}现在我完全感到困惑,我应该在我的请求中添加此字符串.请帮帮我.解决方法:我最近不得不想办法让我的Android应用程序与WCF服

我正在使用httpPut与Android中的服务器通信,我得到的响应代码是500.在与服务器人交谈后,他说准备下面的字符串并发送.

{ “键”: “值”, “关键”: “值”}

现在我完全感到困惑,我应该在我的请求中添加此字符串.

请帮帮我.

解决方法:

我最近不得不想办法让我的AndroID应用程序与WCF服务进行通信并更新特定记录.起初这真的让我很难搞清楚,主要是因为我对http协议不够了解,但我能够通过使用以下内容创建一个PUT:

    URL url = new URL("http://(...your service...).svc/(...your table name...)(...ID of record trying to update...)");    //--This code works for updating a record from the Feed--    httpPut httpPut = new httpPut(url.toString());    JsONStringer Json = new JsONStringer()    .object()        .key("your tables column name...").value("...updated value...")    .endobject();    StringEntity entity = new StringEntity(Json.toString());    entity.setContentType("application/Json;charset=UTF-8");//text/plain;charset=UTF-8    entity.setContentEnCoding(new Basicheader(http.CONTENT_TYPE,"application/Json;charset=UTF-8"));    httpPut.setEntity(entity);     // Send request to WCF service     DefaulthttpClIEnt httpClIEnt = new DefaulthttpClIEnt();    httpResponse response = httpClIEnt.execute(httpPut);                         httpentity entity1 = response.getEntity();     if(entity1 != null&&(response.getStatusline().getStatusCode()==201||response.getStatusline().getStatusCode()==200))    {         //--just so that you can vIEw the response, this is optional--         int sc = response.getStatusline().getStatusCode();         String sl = response.getStatusline().getReasonPhrase();    }    else    {         int sc = response.getStatusline().getStatusCode();         String sl = response.getStatusline().getReasonPhrase();    }

有了这个说法有一个更容易的选择,通过使用一个库,将为您生成更新方法,允许您更新记录,而无需像我上面那样手动编写代码.看起来很常见的2个库是odata4j和restlet.虽然我还没有找到一个明确的odata4j简易教程,但有一个非常好的restlet:http://weblogs.asp.net/uruit/archive/2011/09/13/accessing-odata-from-android-using-restlet.aspx?CommentPosted=true#commentmessage

总结

以上是内存溢出为你收集整理的android – Http Put Request全部内容,希望文章能够帮你解决android – Http Put Request所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/1099140.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-28
下一篇2022-05-28

发表评论

登录后才能评论

评论列表(0条)

    保存