2011-09-08 47 views
1

我用ASIHTTPRequest发送请求到一些URL,并总是得到不同的HTML主体的奇怪的响应。如果我从浏览器或从NSURLRequest类发出相同的请求,我会用正确的HTML正文获得正确的响应。ASIHTTPRequest和NSURLRequest不同的结果

//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

使用Wireshark或者charlesproxy比较请求不同的逻辑,你很快就会发现有什么不同。 – JosephH

回答

0

可能是服务器有不同的请求头