如何从android传递参数到RESTlet webservice?

如何从android传递参数到RESTlet webservice?,第1张

概述我一直在网上寻找如何将参数传递给RESTlet webservice,但似乎没有太多关于RESTlet的教程. 我想从我的Android应用程序中的表单发送一些参数(如果我可以使用JSON这样做会很棒). 我解决了这个问题 至于服务器端 @Postpublic JSONArray serverSideFunction(Representation entity)throws JSONExcep 我一直在网上寻找如何将参数传递给RESTlet webservice,但似乎没有太多关于RESTlet的教程.

我想从我的Android应用程序中的表单发送一些参数(如果我可以使用JsON这样做会很棒).

解决方法 我解决了这个问题

至于服务器端

@Postpublic JsONArray serverSidefunction(Representation entity)throws JsONException {    try {        JsONObject req = (new JsonRepresentation(entity)).getJsonObject();        System.out.println(req.getString(/* filed name */));        System.out.println(req.getString(/* filed name */));        /*          * you can retrIEve all the fIElds here          * and make all necessary actions         */    } catch (IOException e) {        e.printstacktrace();    }}

至于AndroID SIDe

httpClIEnt clIEnt = new DefaulthttpClIEnt();    String responseBody;    JsONObject JsonObject = new JsONObject();    try{        httpPost post = new httpPost(WebService_URL);        JsonObject.put("fIEld1",".........");        JsonObject.put("fIEld2",".........");        StringEntity se = new StringEntity(JsonObject.toString());          post.setEntity(se);        post.setheader(new Basicheader(http.CONTENT_TYPE,"application/Json"));        post.setheader("Content-type","application/Json");        Log.e("webservice request","executing");        ResponseHandler responseHandler = new BasicResponseHandler();        responseBody = clIEnt.execute(post,responseHandler);        /*          * You can work here on your responseBody         * if it's a simple String or XML/JsON response         */    }    catch (Exception e) {        e.printstacktrace();    }

我希望这可能有所帮助

总结

以上是内存溢出为你收集整理的如何从android传递参数到RESTlet webservice?全部内容,希望文章能够帮你解决如何从android传递参数到RESTlet webservice?所遇到的程序开发问题。

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

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

原文地址: http://outofmemory.cn/web/1121848.html

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

发表评论

登录后才能评论

评论列表(0条)

保存