2

Possible Duplicate:
iPhone SDK Xcode 4.2 iOS 5- How do i send a json to url ? (POST and GET) [Resolved]

I have a seemingly easy question. I'm trying to send data from my iPad device to a server using JSON. The thing is, all tutorials I see about sending JSON to the server uses the POST method. My question is, is it possible to send JSON using the GET method? It will be really helpful if you can give me some pointers on how to do it. Thanks.

CalvT
  • 3,123
  • 6
  • 37
  • 54
user1412469
  • 279
  • 5
  • 17
  • 4
    All tutorials use POST because it's the appropriate way to do that putting JSON data into post body. Using get you'd have to put all JSON into URL. – Eimantas May 23 '12 at 11:30
  • Thanks for the reply. I am only asking because using GET is a requirement by my boss. Thanks anyway :) – user1412469 May 24 '12 at 01:52
  • Take a look at: http://stackoverflow.com/questions/7673127/iphone-sdk-xcode-4-2-ios-5-how-do-i-send-a-json-to-url-post-not-get-resolv There is an answer for Get there as well. Also, possible duplicate. – Aleksander Azizi Aug 13 '12 at 15:39
  • @AleksanderAzizi That's not a dupe because the question asks how to do it with a POST. – JeremyP Aug 13 '12 at 16:00
  • The answer on how to do a Get request is there as well. – Aleksander Azizi Aug 13 '12 at 17:08

2 Answers2

1

You should really convince your boss to either use JSON in the body of a POST or use GET Parameters in form of a GET:

http://www.example.com/?Argument1=Wert1&Argument2=Wert2

But the GET example will not be, as you can see, in form of a JSON. Indeed it would be possible to define a custom header where you put your json data in. But I would strongly advise against doing so because IMHO it is not the proper way

Alexander
  • 7,178
  • 8
  • 45
  • 75
1

It's simple. JSON is actually sent via QueryString parameter. For instance to send a dictionary, use following format of URL

http://www.mywebsite.com/service.php?data={"key":"value", "key":"value"}

or an Array of Dictionaries as

http://www.mywebsite.com/service.php?data=[{"key":"value"}, {"key":"value"}]

Make sure you escape your url string properly

atastrophic
  • 3,153
  • 3
  • 31
  • 50