4

私のコードでは、PHPファイルにデータを送信しようとしています

SQL に何かを追加するには、GET メソッドを使用します。

ここまでは Web サイトでフォームを使用する必要がありますが、次のようなデータを閲覧するだけで追加したいと考えています。

http://server.com/add.php?user=ここにいくつかのデータ&message=ここに最後のデータ

これまでのところ、このコードを使用しようとしています:

 NSURL *add = [NSURL URLWithString:@"http://server.com/ios/add.php?user=iPhone App&message=%@",
                                 messageBox.text]; 

 [messageView loadRequest:[NSURLRequest requestWithURL:add]];

ただし、Xcode は、「メソッド呼び出しの引数が多すぎます。1 が必要ですが、2 が必要です」と教えてくれます。

4

3 に答える 3

1

これを試して

NSString *urlString = @"http://server.com/ios/add.php?user=iPhone App&message=";
NSString *escapedString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *add = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@",escapedString, messageBox.text]];
[messageView loadRequest:[NSURLRequest requestWithURL:add]]; 

あなたが使用している必要がありますNSString +stringWithFormat:

于 2012-10-18T12:41:49.603 に答える
0
NSURL *add = [NSURL URLWithString:[NSString stringWithFormat:@"http://server.com/ios/add.php?user=iPhone App&message=%@", messageBox.text]];

これは、URLWithString: が NSString * 型の引数を 1 つしか想定していないためです。NSString の +stringWithFormat: メソッドを使用して、フォーマットされた文字列と引数から NSString オブジェクトを作成します。

于 2012-10-18T12:44:27.280 に答える
0

URLWithString は、文字列または文字列リテラルを受け入れます。これはあなたがそれを行うべき方法です:

NSString* urlString = [NSString stringWithFormat:@"http://server.com/ios/add.php?user=iPhone App&message=%@", messageBox.text];
NSURL *add = [NSURL URLWithString:urlString];  
[messageView loadRequest:[NSURLRequest requestWithURL:add]];
于 2012-10-18T12:43:51.510 に答える