NSURL 对象中的多个参数
我想将多个参数从 iphone sdk 传递到与 mySQL 数据库接口的服务器端 php。
我找到了一些关于如何执行此操作的答案,但我很难弄清楚如何包含多个参数。
我现在所拥有的是
- (IBAction)sendButtonPressed:(id)sender
{
NSString *urlstr = [[NSString alloc] initWithFormat:@"http://server.com/file.php?date=%d", theDate];
NSURL *url = [[NSURL alloc] initWithString:urlstr];
[urlstr release];
[url release];
}
适用于 1 个参数的,但我正在寻找的是类似
http://server.com/file.php?date=value&time=value&category=value&tags=value&entry=value
我将如何做到这一点?
I would like to pass multiple parameters from the iphone sdk to a server-side php which interfaces with a mySQL database.
i found some answers on how to do this, but i'm having a hard time figuring out how to include several parameters.
what i have right now is
- (IBAction)sendButtonPressed:(id)sender
{
NSString *urlstr = [[NSString alloc] initWithFormat:@"http://server.com/file.php?date=%d", theDate];
NSURL *url = [[NSURL alloc] initWithString:urlstr];
[urlstr release];
[url release];
}
which would work for 1 parameter, but what i'm looking for would be something like
http://server.com/file.php?date=value&time=value&category=value&tags=value&entry=value
how would i going about doing this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
- initWithFormat
方法采用多个格式字符串参数。因此,您可以执行以下操作:
- initWithFormat
的工作方式几乎与printf()
及其变体相同。以下是一些
printf()
示例 http://stahlforce。 com/dev/index.php?tool=csc02编辑:变量
nameField、tagsField、dreamEntry
在哪里定义和设置?除非它们是 NSString 并在 @interface 中定义,否则您不能以这种方式使用它们。
我建议对一些值进行硬编码以进行测试:
The
- initWithFormat
method takes multiple arguments for the format string.So you can do things like this:
- initWithFormat
works almost identically toprintf()
and it variants.Here is some
printf()
examples http://stahlforce.com/dev/index.php?tool=csc02Edit: Where are the variables
nameField, tagsField, dreamEntry
defined and set?Unless they are
NSString
s and defined in the@interface
you can not uses them in this way.I suggest hard coding some values for testing:
创建 NSURL 不会打开与服务器的通信。 它只是一个保存 URL 的数据结构。 您想阅读 NSURLConnection。
您以格式传递的所有变量都是真的数字吗?
%d
是数字的占位符;%@
是一个对象。 如果您期望得到一个数字,即使出于测试目的,传递 nil 也是非常令人惊讶的。 它会“起作用”,因为 nil 是 0,但它表明这些并不是真正的数字。Creating an NSURL doesn't open communications with a server. It's just a data structure for holding a URL. You want to read up on NSURLConnection.
Are all the variables you're passing in your format really numbers?
%d
is the placeholder for a number;%@
is an object. It's very surprising to be passing nil if you're expecting a number, even for testing purposes. It'll "work" because nil is 0, but it suggests that these aren't really numbers.