ASIHTTPRequest和NSURLRequest有不同的结果

时间:2011-09-08 09:41:29

标签: objective-c ios asihttprequest nsurlrequest

我使用ASIHTTPRequest向一些网址发送请求,并且总是得到与不同HTML正文的奇怪响应。如果我从浏览器或NSURLRequest类发出相同的请求,我会得到正确的HTML正文响应。

//Here is code of NSURLRequest. I'm getting correct response;
NSURLRequest *request = [NSURLRequest requestWithURL:url];
NSURLResponse *resp = nil;
NSError *err = nil;
NSData *responseData = [NSURLConnection sendSynchronousRequest: request returningResponse: &resp error: &err];
NSString *theString = [[NSString alloc] initWithData:responseData encoding:NSASCIIStringEncoding];
NSLog(@"%@",theString);

//Here is code of ASIHTTPRequest. I'm getting different response. The html body is shorter than original and different;
__block ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setCompletionBlock:^{      
    NSString *responseString = [request responseString];
}];
[request startAsynchronous];

我还尝试使用ASIHTTPRequest发送简单的同步请求,但结果相同。它可能是什么?

1 个答案:

答案 0 :(得分:0)

可能是服务器对不同的请求标头具有不同的逻辑