views:

87

answers:

2

Hello,

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.

+3  A: 

You are getting the warning because NSInteger is a wrapper for int. So you don't need the pointer *. Change the left side of the assignment to just NSInteger responseStatusCode and see if the warning goes away.

Jason McCreary
A: 

Thank you for your reply.

However, there are some warning.

The following is the code

NSInteger *responseStatusCode = [[response statusCode] intValue];
NSLog(@"\nThe status code is %d\n", responseStatusCode);

NSInteger *responseStatusCode = [response statusCode];
[responseStatusCode intValue];
NSLog(@"\nThe status code is %d\n", responseStatusCode);

NSInteger *responseStatusCode = [response statusCode];
NSLog(@"\nThe status code is %d\n", [responseStatusCode intValue]);

I have no ideas why the above 3 methods are wrong and cannot be work.

Thank you.

Questions
You are still making `responseStatusCode` an `NSInteger *`. Drop the pointer cast `*`, it's the problem.
Jason McCreary