URL GET / POST Request objective-c

I need to send a send or send request to localhost:

<?php if(@$_GET['option']) { echo "You said \"{$_GET['option']}\""; }else if(@$_POST['option']) { echo "You said \"{$_POST['option']}\""; } ?> 

using this code:

 NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://localhost/wsh/index.php?option=Hello"]]; NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil]; NSString *get = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding]; 

It works, but once in the code. if it hurts to do this one more time, the application has stopped.

I am trying to use ASIFormDataRequest:

 ASIFormDataRequest *request = [[[ASIFormDataRequest alloc] initWithURL:@"http://localhost/wsh/index.php"] autorelease]; [request setPostValue:@"option" forKey:@"myFormField1"]; [request start]; NSError *error = [request error]; if (!error) { NSString *response = [request responseString]; NSLog(response); }else{ NSLog(@"error"); } 

He says:

 2010-01-07 13:20:34.964 WSH[3351:903] -[NSCFString absoluteURL]: unrecognized selector sent to instance 0x160f8 2010-01-07 13:20:34.966 WSH[3351:903] error 

sry for my english

+4
source share
2 answers

You are using a simple NSString literal where an NSURL object is NSURL : [...] initWithURL:@"http://localhost/wsh/index.php" [...]

Change this to initWithURL:[NSURL URLWithString:@"http://localhost/wsh/index.php"] .

+8
source

I wonder if it is also necessary to switch the value and the key for the column values, i.e. change line

 [request setPostValue:@"option" forKey:@"myFormField1"]; 

to

 [request setPostValue:@"myFormField1" forKey:@"option"]; 
+6
source

All Articles