views:

81

answers:

2

Hi guys! First of all, sorry for my posibly bad english...

I got a surely big stupid question... In my enterprise have an automatic door system, that is opened with a HTTP GET request to a file.

Example:

http://ipaddress/rc.cgi?o=1,50

Where the o=number indicates the amount of seconds that the automatic door will run.

The is no need for authentification or nothing (that is made by LAN Radius).

So, the question is...

How can I make a single button (for example in the springboard) that when you touch it, runs the GET request?

You thing that it should be possible with NSURLConection ?

Thanks for all

+1  A: 

I'm not sure if this is the best way of going about it, but this is how I've achieved something similar in my own app. Just create a new NSData object that hits the required URL, then release it if you don't need to do anything with the returned data:

NSURL *theURL = [[NSURL alloc] initWithString:@"http://ipaddress/rc.cgi?o=1,50"];
NSData *theData = [[NSData alloc] initWithContentsOfURL:theURL];
[theData release];
[theURL release];
James Clarke
A: 

Or just create an NSURLConnection to run asynchronously, then you don't have to worry about the UI hanging and if the delegate is set to nil, you can pretty much forget about it after you've run it.

NSURL * url = [NSURL URLWithString:@"http://ipaddress/rc.cgi?o=1,50"];
NSMutableURLRequest * request = [[NSMutableURLRequest alloc] initWithURL:url];
NSURLConnection * theConnection = [[NSURLConnection alloc] initWithRequest:request delegate:nil];
[request release];
[theConnection release];
Tom Irving
Ah, excellent point! The code I posted doesn't run on the main thread in my application, so I don't need to worry about the UI hanging. Should've mentioned that in my answer.
James Clarke
I will try it, and let you know if it works :D. A lot of thanks
Mph2