NSMutableRequest skd问题
我正在尝试使用 iPhone 拨打网络电话。我以前曾经这样做过并且效果很好,但现在我无法让它工作。我正在尝试使用以下方法调用,文档称该方法在 2.0 及更高版本中可用:
- (void)addValue:(NSString *)value forHTTPHeaderField:(NSString *)field;
我正在尝试构建版本 3.2 和 4.0。
NSMutableURLRequest *request = [NSURLRequest
requestWithURL:url
cachePolicy:NSURLRequestReloadIgnoringCacheData
timeoutInterval:30];
[request addValue:@"0" forHTTPHeaderField:@"Content-Length"];
我收到的错误是运行时错误,显示“
"-[NSURLRequest addValue:forHTTPHeaderField:]: unrecognized selector sent to instance 0x600e0c0"
谁能告诉我我缺少什么,导致此代码无法工作?”
谢谢。
I am trying to make a web call with the iPhone. I have done this before and it works fine but now I can't make it work. I am trying to use the following method call which the documentation says is availble in 2.0 and later:
- (void)addValue:(NSString *)value forHTTPHeaderField:(NSString *)field;
I am attempting to build for version 3.2 and 4.0.
NSMutableURLRequest *request = [NSURLRequest
requestWithURL:url
cachePolicy:NSURLRequestReloadIgnoringCacheData
timeoutInterval:30];
[request addValue:@"0" forHTTPHeaderField:@"Content-Length"];
The error that I'm getting is a runtime error that says
"-[NSURLRequest addValue:forHTTPHeaderField:]: unrecognized selector sent to instance 0x600e0c0"
Can anyone tell me what I am missing that stops this code from working?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在初始化 NSURLRequest 而不是 NSMutableURLRequest。您可能会收到有关它的编译器警告,但运行时会强制转换为不可变的超类。它会一直工作,直到您尝试发送不可变超类没有的消息为止。
You're initializing a NSURLRequest instead of a NSMutableURLRequest. You're probably getting a compiler warning about it but the runtime forces a cast to immutable super class. It works until you try to send a message the immutable super class does not have.