Post JSONArray to REST service

I have a JSONArray that I am creating by iterating through a database using the cursor(Java). The JASONArray I am creating looks like this:

[{"transID":"1001","shiftID":"1","transType":"test","transDateTime":"2013-02-22 15:30:374:021"},
"transID":"1002","shiftID":"2","transType":"ghy","transDateTime":"2013-02-25 11:56:926:020"},
"transID":"1003","shiftID":"3","transType":"ghfm","transDateTime":"2013-02-25 11:56:248:026"}]

I am trying to post the JSONArray above to a RESTful service. I have the URL, UserID and Token, I am having a hard time understanding how to create HTTP post and have looked at the following links:

How to send a JSONObject to a REST service?

Posting a File and Associated Data to a RESTful WebService preferably as JSON

Posting a JSONArray to WCF Service from android

I understand how the first link worked, but I am unclear on how I should implement the userID and token before posting to the REST service.

This is new to me and if anyone could lead me in the right direction it would be appreciated.

Thank you in advance.


Take a look at Jersey's REST client library. There is a class called WebResource. In order to post to a RESTful service, you can invoke the post method. Note that the second argument in the post method contains the POST request entity, which you can encapsulate your JSONArray entity in your request. Alternatively you can use entity method to specify the MediaType (APPLICATION_JSON) of request entity.

链接地址: http://www.djcxy.com/p/48646.html

上一篇: 类型没有dropbox(文件放)api使用? 和如何模仿它?

下一篇: 将JSONArray发布到REST服务