Your application does not fulfill the actual request. The right way to do this is to configure the API for your site so that the site fulfills the request and returns the appropriate data to your application.
Your API will typically consist of several endpoints that return data formatted for your application. For example, you can create a PHP or Python page that queries your database for all messages for a given user and returns them in a JSON or XML array. (The data format is completely up to you. There is a framework for parsing both formats available for iOS.)
For example, let's say you have a PHP page on your server that returns the current day of the week. Your PHP will look something like this:
<?php echo date("l"); ?>
Imagine you saved this as http://example.com/dayoftheweek.php
I recommend using ASIHTTPRequest to make HTTP requests from your application. However, release and configure the connection to your PHP page. Assuming you have ASIHTTPRequest configured in your project, here is what the request looks like:
NSURL *url = [NSURL URLWithString:@"http://example.com/dayoftheweek.php"] ASIHTTPRequest *request = [[ASIHTTPRequest alloc] initWithURL:url]; [request setDelegate:self];
Now you need to implement ASIHTTPRequest delegation methods to analyze the returned data. Here is a method that processes a completed request:
- (void)requestFinished:(ASIHTTPRequest *)request{
To implement the API, your PHP pages will be more complex. You would build a more complex query by passing variables and such, and the PHP page would act like a regular web service, returning the data you requested.
Moshe source share