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 03-11-2009, 11:35 AM   #1 (permalink)
New Member
 
Join Date: Mar 2009
Posts: 3
robgreensmith is on a distinguished road
Default HTTP post to php script

I need to setup a http post from my app to a php script on a localhost server ie http://localhost/test2.php?param1=123

how can i do this?

the php script access a local database and echo's the results..
Is it possible to store these echo'd results in a NSMutableData and if so how can i do this??

Any help appreciated!

Rob
robgreensmith is offline   Reply With Quote
Old 03-11-2009, 11:48 AM   #2 (permalink)
Registered Member
 
RickMaddy's Avatar
 
Join Date: Oct 2008
Location: Denver, CO
Posts: 2,121
RickMaddy will become famous soon enough
Default

Search here and/or Google. You will find plenty of code examples for performing HTTP form posts.

Some of the classes involved are NSURLConnection and NSURLRequest.

But if your URL is just as you posted then this is not a HTTP POST but an HTTP GET. That is much easier.

Just use the above classes passing in your URL with whatever query parameters you need. The response will contain whatever is sent back (text or HTML). You can then parse that data as needed.
RickMaddy is offline   Reply With Quote
Old 03-11-2009, 01:31 PM   #3 (permalink)
New Member
 
Join Date: Mar 2009
Posts: 3
robgreensmith is on a distinguished road
Default

Has anybody got any examples or links to examples of http get??

Cant find much on google on it?

Thanks
Rob
robgreensmith is offline   Reply With Quote
Old 03-11-2009, 01:37 PM   #4 (permalink)
Tutorial Author
 
Join Date: Feb 2009
Posts: 49
chewbocka is on a distinguished road
Default

Quote:
Originally Posted by robgreensmith View Post
Has anybody got any examples or links to examples of http get??
I'm using something like this for get requests.

Code:
NSMutableURLRequest *request = [[NSMutableRequest alloc] initWithURL: [NSURL URLWithString: url]];
[request setHTTPMethod: @"GET"];

NSData *response = [NSURLConnection sendSynchronousRequest: request returningResponse: nil error: nil];
NSString *stringResponse = [[NSString alloc] initWithData: response encoding: NSUTF8StringEncoding];
__________________
blog | twitter
chewbocka is offline   Reply With Quote
Old 03-12-2009, 05:06 AM   #5 (permalink)
New Member
 
Join Date: Mar 2009
Posts: 3
robgreensmith is on a distinguished road
Default

Quote:
Originally Posted by chewbocka View Post
I'm using something like this for get requests.

Code:
NSMutableURLRequest *request = [[NSMutableRequest alloc] initWithURL: [NSURL URLWithString: url]];
[request setHTTPMethod: @"GET"];

NSData *response = [NSURLConnection sendSynchronousRequest: request returningResponse: nil error: nil];
NSString *stringResponse = [[NSString alloc] initWithData: response encoding: NSUTF8StringEncoding];


Worked perfectly thanks a million!!!
robgreensmith is offline   Reply With Quote
Old 03-12-2009, 05:45 AM   #6 (permalink)
Registered Member
 
Join Date: Dec 2008
Posts: 429
lbendlin is on a distinguished road
Default

before anyone gets the wrong impression - there is no localhost http server on the phone, and definitely no PHP support...
lbendlin is offline   Reply With Quote
Old 03-12-2009, 09:29 AM   #7 (permalink)
[self setSkills: ∞];
 
Join Date: Dec 2008
Age: 29
Posts: 111
cjpearl is on a distinguished road
Default

WHAT!!! I've been duped, REFUND PLEASE.
__________________
Want a free copy of my MMS app? http://www.iphonedevsdk.com/forum/pr...plication.html
cjpearl is offline   Reply With Quote
Old 03-12-2009, 10:31 AM   #8 (permalink)
Registered Member
 
Join Date: Dec 2008
Posts: 429
lbendlin is on a distinguished road
Default

didn't you read the fine print? No ATM included either.
lbendlin is offline   Reply With Quote
Old 03-12-2009, 10:37 AM   #9 (permalink)
[self setSkills: ∞];
 
Join Date: Dec 2008
Age: 29
Posts: 111
cjpearl is on a distinguished road
Default

I report prolem but developurs not give my money back!!!!
__________________
Want a free copy of my MMS app? http://www.iphonedevsdk.com/forum/pr...plication.html
cjpearl is offline   Reply With Quote
Reply

Bookmarks

Tags
http, nsmutabledata, php, post

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: 338
3 members and 335 guests
guusleijsten, Kryckter, LEARN2MAKE
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,649
Threads: 94,113
Posts: 402,880
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Anwerbl
Powered by vBadvanced CMPS v3.1.0

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