gpt4 book ai didi

iphone - 使用 %@ 设置 NSURL 使值等于 %@ 而不是插入 %@

转载 作者:行者123 更新时间:2023-12-03 20:22:36 25 4
gpt4 key购买 nike

我正在使用 ASIHTTP 并尝试对站点执行 GET 请求:

NSURL *url = [[NSURL URLWithString:@"/verifyuser.aspx?user=%@" relativeToURL:@"http://domain.com"],userName  retain];       
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setTemporaryFileDownloadPath:@"myfile2.txt"];
[request setDownloadDestinationPath:@"myfile.txt"];

[request startSynchronous];

但是,当我在 [request startSynchronous] 上放置断点并进入调试器时,请求对象的 url 值等于 userName 变量。我正在尝试将 userName 变量插入到字符串中,然后将其用作 url,因此我的 NSURL 声明中有些问题。

感谢您的帮助!

最佳答案

您的代码不正确,您没有正确进行字符串格式化,它应该如下所示:

NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"/verifyuser.aspx?user=%@", userName] relativeToURL:@"http://domain.com"];

请注意,您不需要保留 URL,因为您只需将其传递给请求即可。

关于iphone - 使用 %@ 设置 NSURL 使值等于 %@ 而不是插入 %@,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2075444/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com