简体   繁体   English

在Android中调用Java RESTful Web服务

[英]Calling Java RESTful webservice in Android

i have created a Java Restful Web service . 我已经创建了Java Restful Web服务 Now i want to access it in Android . 现在我想在Android中访问它。 There are different methods in Webservice. Webservice中有不同的方法。 Web service is running on http://192.15.10.62:8080 . Web服务正在http://192.15.10.62:8080上运行。 how should i call a method named getGreetingMsg() in webservice which take a string argument and return a simple String message. 我应该如何在webservice中调用名为getGreetingMsg()的方法,该方法采用字符串参数并返回简单的String消息。

Web service Details Web服务详细信息

Project name RestFulWS 项目名称RestFulWS

package Name rest.ws.server 软件包名称rest.ws.server

class Name helloAndroid 类名helloAndroid

Method Name getGreetingMsg(string argument) 方法名称getGreetingMsg(字符串参数)

any help will be appreciated. 任何帮助将不胜感激。

Simply with an HTTP client like AndroidHttpClient . 只需使用HTTP客户端(例如AndroidHttpClient)即可

EDIT: RESTful web service is accessible through URL like: 编辑: RESTful Web服务可通过URL进行访问,例如:

http://yourserver/someservice/<categoryID>/<objectID>

So, you can test your webservice from a web browser like Internet Explorer or Mozilla Firefox. 因此,您可以从Web浏览器(例如Internet Explorer或Mozilla Firefox)测试Web服务。

Then, on Android, use HTTP Get request and the AndroidHttpClient. 然后,在Android上,使用HTTP Get请求和AndroidHttpClient。

Don't forget to set the INTERNET permission in your AndroidManifest.xml too 别忘了也在AndroidManifest.xml中设置INTERNET权限

It depend on the Web server you are using because each type of server will have its own URL to service hosted on it. 它取决于您使用的Web服务器,因为每种类型的服务器都将拥有自己的URL来托管服务。 If you are using JBOSS server then your URL looks like this IP:PORT/projectname/webservicename/method name 如果您使用的是JBOSS服务器,则您的URL如下所示:IP:PORT / projectname / webservicename / method name

Sounds like you're not sure how to approach your own API. 听起来好像您不确定如何使用自己的API。 If your API supports GET, then open a web browser and try some GET commands. 如果您的API支持GET,请打开Web浏览器并尝试一些GET命令。 Once you have a GET statement working, work through this tutorial: http://sarangasl.blogspot.com/2011/06/android-login-screen-using-httpclient.html . 使用GET语句后,请完成本教程: http : //sarangasl.blogspot.com/2011/06/android-login-screen-using-httpclient.html

Once you're set with POST, turn off GET in your webserver. 设置为POST后,请在网络服务器中关闭GET。

Good luck! 祝好运!

db D b

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM