Iphone NSHTTPURLRequest头

Iphone NSHTTPURLRequest头,iphone,http-status-codes,Iphone,Http Status Codes,我想从一个网站上得到一些信息。我已经得到了网站的HTML代码。但是,我想获得更多的网站标题信息(例如http状态码) 在阅读苹果图书馆之后,我发现有两种方法可以显示这些信息。但是,我只能使用其中一种方法(有警告),不能使用另一种方法 下面是代码 NSHTTPURLResponse *response = nil; NSError *error = nil; NSData *responseData = [NSURLConnection sendSynchronousRequest:request

我想从一个网站上得到一些信息。我已经得到了网站的HTML代码。但是,我想获得更多的网站标题信息(例如http状态码)

在阅读苹果图书馆之后,我发现有两种方法可以显示这些信息。但是,我只能使用其中一种方法(有警告),不能使用另一种方法

下面是代码

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);
NSHTTPURLResponse*response=nil;
n错误*错误=nil;
NSData*responseData=[NSURLConnection sendSynchronousRequest:request ReturnInResponse:&响应错误:&错误];
NSString*data=[[NSString alloc]initWithData:responseData编码:NSUTF8StringEncoding];
NSDictionary*ResponseAllHeaderFields=[response allHeaderFields];
//如何将NSDictionary转换为NSString,我无法使用NSLog显示信息

NSLog(ResponseAllHeaderFields);// 您会收到警告,因为NSInteger是
int
的包装器。因此,您不需要指针
*
。将赋值的左侧更改为just
NSInteger responseStatusCode
,然后查看警告是否消失。

您将收到警告,因为NSInteger是
int
的包装器。因此,您不需要指针
*
。将作业的左侧改为“仅显示提示应答状态代码”,然后查看警告是否消失。

谢谢您的回复

然而,也有一些警告

下面是代码

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]);
我不知道为什么上述三种方法都是错误的,不能有效


谢谢。

谢谢您的回复

然而,也有一些警告

下面是代码

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]);
我不知道为什么上述三种方法都是错误的,不能有效


谢谢。

您仍在制作
responseStatusCode
一个
NSInteger*
。放下指针,这就是问题所在。您仍在使
responseStatusCode
成为
NSInteger*
。删除指针强制转换
*
,这就是问题所在。您可以执行
NSLog(@“头字段是%@”,responseAllHeaderFields)您可以执行
NSLog(@“标题字段为%@”,响应所有标题字段)