Search code examples
iosjsonnsurlconnection

send JSON and query parameters in a same request using NSURLConnection


I need to send the JSON data and query params in a same request, is there any way to achieve the same using NSURLConnection?

Help appreciated.

eg: request:

username="test"&password="password"&"location"={"latitude":12,"longitude":"78"}

Here location is a JSON data.


Solution

  • Yes.

    You can append them to the URL as parameters, as your example shows, and issue a GET, or put part or all of the parameters in the http body, and issue a POST. Since JSON data is usually of long, indeterminate length, most people put the JSON in the body, and use parameters or http headers for the others, with POST.