Send POST data to browser
Send POST data to browser
- Subject: Send POST data to browser
- From: Bartosz Białecki <email@hidden>
- Date: Thu, 17 Sep 2009 12:26:19 +0200
- Organization: Nowa Poczta Wirtualnej Polski S.A. http://www.wp.pl/
Hi,
I'm new in programming for iPhone and I have a problem. I have a website
with login form and I want to write a program on iPhone which open this
website without authentication. I thought to launch a brwoser from my
application and send a POST data with username and password, but I have
no idea how to do that.
I can launch browser with url using this code:
NSURL *url = [NSURL URLWithString: @"https://www.example.com/index.php"];
[[UIApplication sharedApplication] openURL: url];
but I don't know how to send post data.
I tried also another solution: send post data from my application to
website and then get a response, but then I don't know how to open
returned page in browser. I used this code:
NSString *postString = [[NSString alloc]
initWithFormat:@"username=%@&password=%@", [self urlEncodeValue:
username], [self urlEncodeValue: password]];
NSData *requestData = [NSData dataWithBytes: [postString UTF8String]
length: [postString length]];
NSURL *url = [NSURL URLWithString: @"https://www.example.com/index.php"];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:
url];
[request setHTTPMethod: @"POST"];
[request setValue: @"application/x-www-form-urlencoded"
forHTTPHeaderField: @"Content-Type"];
[request setHTTPBody: requestData];
NSURLResponse *response;
NSError *error;
NSData *returnData = [NSURLConnection sendSynchronousRequest: request
returningResponse: &response error: &error];
NSString *dataReturned = [[NSString alloc] initWithData: returnData
encoding: NSASCIIStringEncoding];
I will be appreciate of any help.
Best regards
Bartosz Bialecki
----------------------------------------------------
Wiedza. Wikipedia. Encyklopedia.
Zrozum otaczający Cię świat:
http://klik.wp.pl/?adr=http://wikipedia.wp.pl&sid=857
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden