NSURL 对象中的多个参数

发布于 2024-07-22 06:57:02 字数 582 浏览 7 评论 0原文

我想将多个参数从 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

云淡风轻 2024-07-29 06:57:02

- initWithFormat 方法采用多个格式字符串参数。

因此,您可以执行以下操作:

  NSString *urlstr = [[NSString alloc] initWithFormat:@"http://server.com/file.php?date=%d&second=%d&third=%d", theDate, 2, thirdIVar];

- initWithFormat 的工作方式几乎与 printf() 及其变体相同。

以下是一些 printf() 示例 http://stahlforce。 com/dev/index.php?tool=csc02

编辑:变量 nameField、tagsField、dreamEntry 在哪里定义和设置?

除非它们是 NSString 并在 @interface 中定义,否则您不能以这种方式使用它们。

我建议对一些值进行硬编码以进行测试:

    NSString *urlstr = [[NSString alloc] initWithFormat:@"http://server.com/file.php?date=%@&time=%@&name=%@&category=%d&tags=%@&entry=%@", nil, nil, @"Name", nil, @"Tags", @"Dream"];

The - initWithFormat method takes multiple arguments for the format string.

So you can do things like this:

  NSString *urlstr = [[NSString alloc] initWithFormat:@"http://server.com/file.php?date=%d&second=%d&third=%d", theDate, 2, thirdIVar];

- initWithFormat works almost identically to printf() and it variants.

Here is some printf() examples http://stahlforce.com/dev/index.php?tool=csc02

Edit: Where are the variables nameField, tagsField, dreamEntry defined and set?

Unless they are NSStrings and defined in the @interface you can not uses them in this way.

I suggest hard coding some values for testing:

    NSString *urlstr = [[NSString alloc] initWithFormat:@"http://server.com/file.php?date=%@&time=%@&name=%@&category=%d&tags=%@&entry=%@", nil, nil, @"Name", nil, @"Tags", @"Dream"];
再可℃爱ぅ一点好了 2024-07-29 06:57:02

创建 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文