URL-GET/POST-Anfrage objective-c
Habe ich das senden von get-oder post-request an localhost:
<?php
if(@$_GET['option']) {
echo "You said \"{$_GET['option']}\"";
}else if(@$_POST['option']) {
echo "You said \"{$_POST['option']}\"";
}
?>
ive, das mit diesem 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];
es funktioniert, aber eine Zeit, in code. wenn krank, tun Sie es ein weiteres mal, die Anwendung zu beenden.
Im versuchen, 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");
}
er sagt:
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 für mein Englisch
InformationsquelleAutor kosmaks | 2010-01-07
Du musst angemeldet sein, um einen Kommentar abzugeben.
Sind Sie mit einem einfachen
NSString
wörtliche wo einNSURL
Objekt erwartet wird: [...]initWithURL:@"http://localhost/wsh/index.php"
[...]Ändern
initWithURL:[NSURL URLWithString:@"http://localhost/wsh/index.php"]
.InformationsquelleAutor Nikolai Ruhe
Frage ich mich, ob auch Sie wechseln sollten, den Wert und die Taste für die post-Werte, dh ändern Sie die Zeile
zu
InformationsquelleAutor epatel