 |
 |
|
 |
03-11-2009, 12:35 PM
|
#1 (permalink)
|
|
New Member
Join Date: Mar 2009
Posts: 3
|
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
|
|
|
03-11-2009, 12:48 PM
|
#2 (permalink)
|
|
New Member
Join Date: Oct 2008
Location: Denver, CO
Posts: 2,121
|
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.
|
|
|
03-11-2009, 02:31 PM
|
#3 (permalink)
|
|
New Member
Join Date: Mar 2009
Posts: 3
|
Has anybody got any examples or links to examples of http get??
Cant find much on google on it?
Thanks
Rob
|
|
|
03-11-2009, 02:37 PM
|
#4 (permalink)
|
|
Tutorial Author
Join Date: Feb 2009
Posts: 49
|
Quote:
Originally Posted by robgreensmith
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];
|
|
|
03-12-2009, 06:06 AM
|
#5 (permalink)
|
|
New Member
Join Date: Mar 2009
Posts: 3
|
Quote:
Originally Posted by chewbocka
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!!!
|
|
|
03-12-2009, 06:45 AM
|
#6 (permalink)
|
|
Registered Member
Join Date: Dec 2008
Posts: 427
|
before anyone gets the wrong impression - there is no localhost http server on the phone, and definitely no PHP support...
|
|
|
03-12-2009, 10:29 AM
|
#7 (permalink)
|
|
[self setSkills: ∞];
Join Date: Dec 2008
Age: 26
Posts: 109
|
WHAT!!! I've been duped, REFUND PLEASE.
|
|
|
03-12-2009, 11:31 AM
|
#8 (permalink)
|
|
Registered Member
Join Date: Dec 2008
Posts: 427
|
didn't you read the fine print? No ATM included either.
|
|
|
03-12-2009, 11:37 AM
|
#9 (permalink)
|
|
[self setSkills: ∞];
Join Date: Dec 2008
Age: 26
Posts: 109
|
 I report prolem but developurs not give my money back!!!!
|
|
|
 |
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
» Advertisements |
» Online Users: 494 |
| 62 members and 432 guests |
| alexcrick209, atsd, AXP, bbc z, bensj, BostonMerlin, brianmethod, cakeisalie, cornishGeeza, CunningCat, danny8, davek, dbarrett, dda, deden, DevJustin, Dorald, embedded, ggalante, gonk, harrytheshark, healthyutech, iPhoneDevelopment, IphoneSdk, Jeremy1026, jharrah, kjelleinar, krowczyk, Link, MacSteve85, markbuchanan, MarkC, mebarron, naomipunkclan, nibby, NicolasD, Noise, pbcbvba, pieter78, racer_X, raheel, Sckah, Sesa, SimonK, sjdev, soulless, StefanL, Tambourin, the1nz4ne, treazer, tturk, Type25, virvalid, Vivek Nirkhe, Vonswanko, wassupdoc, winklllll, x2on |
| Most users ever online was 779, 05-11-2009 at 10:55 AM. |
» Stats |
Members: 21,507
Threads: 35,791
Posts: 156,790
Top Poster: smasher (2,449)
|
| Welcome to our newest member, soulless |
|