웹 사이트에서 정보를 얻고 싶습니다. 이미 웹 사이트의 HTML 코드가 있습니다. 그러나 웹 사이트의 헤더 정보 (예 : http 상태 코드)를 더보고 싶습니다.NSHTTPURL 요청 헤더
사과 라이브러리를 읽은 후 해당 정보를 표시 할 수있는 두 가지 방법이 있음을 발견했습니다. 그러나, 나는 오직 하나의 방법 (경고 있음)을 사용할 수 있으며, 또 다른 방법은 사용할 수 없다.
다음은 코드입니다.
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);
게다가 헤더 정보를 얻는 다른 방법이 있습니까?
대단히 감사합니다.
당신은 할 수 있습니다. NSLog (@ "헤더 필드는 % @", responseAllHeaderFields입니다;)' –