문제

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.

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top