Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 02-25-2011, 12:34 AM   #1 (permalink)
Registered Member
 
Join Date: Feb 2011
Location: Chicago, IL
Posts: 15
Gefthebest is on a distinguished road
Default PHP $_GET or $_POST and URLRequest

Hi all,

I've been researching alot on using mysql databases data for an iphone app.
I was wondering how to send PHP $_GET, $_POST or $_REQUEST requests from the app?

I know about:

Code:
NSURL *urlToSend = [[NSURL alloc] initWithString: @"www.mypage.com/myscript.php?mynumber=99&myname=codezy"];

NSURLRequest *urlRequest = [NSURLRequest requestWithURL:urlToSend   
                                            cachePolicy:NSURLRequestReturnCacheDataElseLoad                                                               
                                   timeoutInterval:30];

NSData *urlData;
NSURLResponse *response;
NSError *error;
urlData = [NSURLConnection sendSynchronousRequest:urlRequest  
                                returningResponse:&response 
                                            error:&error];
But I don't really understand what URLRequest does extensively? From the name and reference Library it says it loads the URL and then you tell it what to do with the data it receives...

What I ultimately want to do is:
I send a request with a string/text argument "myArg", and on the server side it does a bunch of stuff (checks in the database for the existence of that argument) and returns TRUE or FALSE...

thanks for the help
Gefthebest is offline   Reply With Quote
Old 02-25-2011, 02:08 AM   #2 (permalink)
Registered Member
 
Join Date: Oct 2009
Location: Amsterdam, The Netherlands
Posts: 782
TUX2K is on a distinguished road
Default

$_GET in php are just simple get parameter for the HTTP protocol.
The get parameters are the easiest to use, you are already using them:
www.mypage.com/myscript.php?mynumber=99&myname=codezy

The parts of the URL I made bold are get parameter.

Post is bit more difficult, but you can use bigger chucks of data in post them in get.
When you want to use post is would suggest use ASIHttpRequest's ASIFormDataRequest.

About handeling the recieved data, it in the urlData part of your example.
Just do:
Code:
NSLog(@"Urldata: %@", urlData);
Or
NSstring *responseString = [[NSString alloc] initWithData:urlData];
NSLog(@"responseString: %@", responseString);
[responseString release], responseString = nil;
__________________
If my answer helped you, you might want to help me.
Make a donation via PayPal.

Last edited by TUX2K; 02-25-2011 at 02:11 AM.
TUX2K is offline   Reply With Quote
Old 03-01-2011, 03:13 PM   #3 (permalink)
Registered Member
 
Join Date: Feb 2011
Location: Chicago, IL
Posts: 15
Gefthebest is on a distinguished road
Default

Quote:
Originally Posted by TUX2K View Post
$_GET in php are just simple get parameter for the HTTP protocol.
The get parameters are the easiest to use, you are already using them:
www.mypage.com/myscript.php?mynumber=99&myname=codezy

The parts of the URL I made bold are get parameter.

Post is bit more difficult, but you can use bigger chucks of data in post them in get.
When you want to use post is would suggest use ASIHttpRequest's ASIFormDataRequest.

About handeling the recieved data, it in the urlData part of your example.
Just do:
Code:
NSLog(@"Urldata: %@", urlData);
Or
NSstring *responseString = [[NSString alloc] initWithData:urlData];
NSLog(@"responseString: %@", responseString);
[responseString release], responseString = nil;
Thanks alot for the info. COncerning ASIHttpRequest, is it recognized by Apple? Basicaly if I want to add an app to the app store will it be accepted (any idea..?) if it contains this API?

Thanks
Gefthebest is offline   Reply With Quote
Old 03-02-2011, 01:51 AM   #4 (permalink)
Registered Member
 
Join Date: Oct 2009
Location: Amsterdam, The Netherlands
Posts: 782
TUX2K is on a distinguished road
Default

Yes ASIHttpRequest is allowed by apple, I use it all the time.
__________________
If my answer helped you, you might want to help me.
Make a donation via PayPal.
TUX2K is offline   Reply With Quote
Reply

Bookmarks

Tags
database, mysql, php, url

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 374
19 members and 355 guests
Absentia, akphyo, apatsufas, BinHex, cpsclicker, dre, Error404, Gaz, gmarro, jeroenkeij, Kirkout, MarkC, mottdog, Music Man, PavelMik, teebee74, whitey99, Wikiboo
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,666
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, cpsclicker
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 03:15 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0