views:

183

answers:

1

Hi, 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.

A: 

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.

TechZen
Or to be more direct: replace NSURLRequest with NSMutableURLRequest
tc.