NSHTTPURLRequest header

Discussion in 'iOS Programming' started by MarkSiu, Jun 28, 2010.

  1. macrumors newbie

    Joined:
    Jun 27, 2010
    #1
    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.

    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.
     
  2. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    NSIntegers are not objects. They are typedefs.
     

Share This Page