从http服务器检索xml流 - android问题
在我的应用程序中,我必须从服务器获取一些作业的列表。在服务器上,我有一个方法,例如 fetchAssignments(int ,String),它采用两个值作为其参数。
- 期间(今天、当前月份或本周) - 整数
- 用户 ID - 字符串
此函数以 XML 流的形式返回作业列表。我知道如何连接到 http 服务器。但我不知道如何在服务器上调用该方法并将这些参数传递给它。谁能建议我更好的方法......?
In my applicaion, I have to fetch a list of some assignments from a server. On the server, i have a method,say fetchAssignments(int ,String), which takes two values as its parameters.
- Period ( today,current month or current week ) - integer
- user id - String
This function returns the list of assignments as an XML stream. I know how i can get connected to the http server. But i m not getting how i can invoke that method on the server and pass these parameters to it. Could anyone suggest me a better way of doing it...?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 HTTP GET 请求从服务器请求 XML 作为 InputStream,并将参数作为请求参数传递:
使用类似下面的方法,您可以从服务器获取流:
然后您可以使用“Simple” (http://simple.sourceforge.net/) XML 库,用于将 XML 解析为类似 JAXB 的实体:
我正在这样做,只是使用 REST 服务,所以我不使用请求参数。
You could just request the XML as InputStream from the server using a HTTP GET request, and pass the parameters as request parameters:
With a method something like the below you can get the stream from the server:
And then you could use the "Simple" (http://simple.sourceforge.net/) XML library to parse the XML into JAXB-like entities:
I am doing pretty much that, just with a REST service, so I don't use request parameters.
根据语言,您可以通过 URL HTTP 请求或使用 POST 传递参数。在类的构造函数中(假设它是一个网页?.php?.aspx?)检索这些值并将它们传递给上面提到的方法?
Depending on the language you could pass the parameters through the URL HTTP request or using POST. In the constructor for the class (assuming its a webpage? .php? .aspx?) retrieve those values and pass them to the method mentioned above?