php - iOS Xcode NSURL 参数太多

标签 php objective-c ios xcode nsurl

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

为了将内容添加到我的 SQL 中,我使用 GET 方法。

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

http://server.com/add.php?user=some data here&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”

最佳答案

试试这个

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:

关于php - iOS Xcode NSURL 参数太多,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12954866/

相关文章:

php - 使用 OpenID 在 CodeIgniter 中使用 Google 帐户登录

php - 从 now() 到周日午夜的秒数

php - 存储桶上的 S3 List Objects 请求以获取额外的 key (> 1000)

iphone - 我应该如何在导航栏上绘制自定义按钮

objective-c - 替换 CoreWLAN 已弃用的功能

ios - Objective C 相当于 cURL 来处理 JSON

iphone - 在横向模式下启动(启动图像)?

javascript - 选中复选框时在php中调用js函数

iphone - 为什么 performSelector : crash my application?

ios - 如何为不同的 UITableView 部分使用不同的 TableView 单元格类