View Full Version : NSHTTPURLRequest header

Jun 28, 2010, 09:08 PM

I would like to get some information from a website. I have already got the HTML code of the website. However, I would like to get more header information of the website (e.g. http status code)

After read the apple library, I found that there are 2 methods which can display those information. However, I can only use one of the methods (has warning), another cannot be used.

The following is the code.

NSHTTPURLResponse *response = nil;
NSError *error = nil;
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];

NSString *data=[[NSString alloc]initWithData:responseData encoding:NSUTF8StringEncoding];

NSDictionary *responseAlllHeaderFields = [response allHeaderFields];
// how can I convent the NSDictionary to the NSString, I cannot use the NSLog to display the information
NSLog(responseAlllHeaderFields); // <-- wrong

// returns the HTTP status code for the response
NSInteger *responseStatusCode = [response statusCode];
// warning: initialization makes pointer from integer without a cast
NSLog(@"\nThe status code is %d\n", responseStatusCode);

Besides, are there are any other methods to get the header informatino?
Thank you very much.

Jun 29, 2010, 02:16 AM
NSIntegers are not objects. They are typedefs.