O'Reilly logo

iOS 5 Programming Cookbook by Vandad Nahavandipoor

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

8.5. Sending HTTP GET Requests with NSURLConnection

Problem

You want to send a GET request over the HTTP protocol and perhaps pass parameters along your request to the receiver.

Solution

By convention, GET requests allow parameters through query strings of the familiar form:

http://example.com/?param1=value1&param2=value2...

You can use strings to provide the parameters in the conventional format.

Discussion

A GET request is a request to a web server to retrieve data. The request usually carries some parameters, which are sent in a query string as part of the URL.

To let you test parameter passing, I have prepared a simple GET web service at the following address: http://pixolity.com/get.php. If you open this URL in your browser, you will see something similar to Figure 8-1.

The example GET web service opened in a web browser

Figure 8-1. The example GET web service opened in a web browser

So our web browser is able to open this URL just fine, and you can see that the web service is able to detect query string parameters and GET parameters. Now if you open the following URL (http://pixolity.com/get.php?param1=First&param2=Second) in your browser, you will see results similar to those shown in Figure 8-2.

Query string parameters sent to the GET web service

Figure 8-2. Query string parameters sent to the GET web service

To simulate sending query string parameters in a GET request to the same web service ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required