开发者

NSMutableRequest skd problem

开发者 https://www.devze.com 2023-01-03 16:23 出处:网络
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 avai

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 avail开发者_运维知识库ble 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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消