4
6
localhostにgetまたはpostリクエストを送信する必要があります。
このコードを使用して:
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];
動作しますが、コードは1回です。 もう1度病気をやると、アプリケーションは終了します。
私は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"); }
それは言います:
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
私の英語を叫ぶ
2 回答
8
あなたは NSURL`オブジェクトが期待されるプレーンな
NSString`リテラルを使用しています:[…] initWithURL:@" http://localhost/wsh/index.php "
[…]
これを `initWithURL:[NSURL URLWithString:@" http://localhost/wsh/index.php "]`に変更します。
6
また、投稿値の値とキーを切り替える必要がありますか、行を変更する
[request setPostValue:@"option" forKey:@"myFormField1"];
to
[request setPostValue:@"myFormField1" forKey:@"option"];