Php iOS Xcode NSURL参数太多

Php iOS Xcode NSURL参数太多,php,objective-c,ios,xcode,nsurl,Php,Objective C,Ios,Xcode,Nsurl,在我的代码中,我试图向我的PHP文件发送一些数据 为了向SQL中添加内容,我使用GET方法 到目前为止,我需要在网站上使用一个表单,但我想在浏览时添加数据,例如: 此处的数据&消息=此处的最后一个数据 到目前为止,我正在尝试使用此代码: NSURL *add = [NSURL URLWithString:@"http://server.com/ios/add.php?user=iPhone App&message=%@",

在我的代码中,我试图向我的PHP文件发送一些数据

为了向SQL中添加内容,我使用GET方法

到目前为止,我需要在网站上使用一个表单,但我想在浏览时添加数据,例如:

此处的数据&消息=此处的最后一个数据

到目前为止,我正在尝试使用此代码:

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

 [messageView loadRequest:[NSURLRequest requestWithURL:add]];
然而,Xcode告诉我:“方法调用的参数太多,应该是1,但有2”

试试这个

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:

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]];

这是因为URLWithString:只需要一个NSString*类型的参数。使用NSString的+stringWithFormat:方法从格式化字符串和参数生成NSString对象。

请记住,您还需要转义字符串以删除空格,在iPhone应用程序中使用空格发出HTTP请求将出错。非常感谢!但是,如何使应用程序删除空间?当我用空格替换a+时,它起作用了
NSURL *add = [NSURL URLWithString:[NSString stringWithFormat:@"http://server.com/ios/add.php?user=iPhone App&message=%@", messageBox.text]];