1

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.

Community
  • 1
  • 1
osbt
  • 131
  • 5
  • 12
  • 1
    Sorry but in which programming language? – Filippo De Luca Jan 21 '14 at 23:36
  • I am trying to do this with Java. Thank you. – osbt Jan 22 '14 at 00:03
  • What part of those links did you not understand? To me, they seem straightforward so you'll need to tell us a little more about what's tripping you up. – Chris Thompson Jan 22 '14 at 00:15
  • Thanks for the reply/feedback Chris, I updated my question. 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. – osbt Jan 22 '14 at 00:45

1 Answers1

3

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.

tonga
  • 11,749
  • 25
  • 75
  • 96