gpt4 book ai didi

iphone - NSURLConnection、NSMutableURLRequest 设置范围错误

转载 作者:行者123 更新时间:2023-12-03 18:42:29 26 4
gpt4 key购买 nike

我正在尝试使用以下方法实现下载恢复功能setValue:forHTTPHeaderField。但每当我使用该方法时,我都会得到一个

[NSURLRequest setValue:forHTTPHeaderField:]: unrecognized selector sent to instance 0x4e0b710 2011-08-08 22:44:36.469 Patch[9140:207] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSURLRequest setValue:forHTTPHeaderField:]: unrecognized selector sent to instance 0x4e0b710'

错误。

如果没有该方法,我的代码可以正常工作,但是当我包含此代码时,我收到上面的错误

NSMutableURLRequest* request = [NSURLRequest requestWithURL:[NSURL URLWithString:URL]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:60.0];

//---------------- setting range for download resume -----------------------
NSString* range = @"bytes=";
range = [range stringByAppendingString:[[NSNumber numberWithInt:offset] stringValue]];
range = [range stringByAppendingString:@"-"];
NSLog(@"range: %@", range);

[request setValue:range forHTTPHeaderField:@"Range"];

请帮助我...非常感谢

最佳答案

您需要使用 NSMutableURLRequest 创建一个 NSMutableURLRequest

NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:URL]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:60.0];

关于iphone - NSURLConnection、NSMutableURLRequest 设置范围错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6983112/

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