【问题标题】:ASIHTTPRequest and NSURLRequest different resultASIHTTPRequest 和 NSURLRequest 不同的结果
【发布时间】:2011-09-08 18:12:06
【问题描述】:

我使用 ASIHTTPRequest 向某个 url 发送请求,但总是得到不同 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 发送简单的同步请求,但结果相同。可能是什么?

【问题讨论】:

  • 使用wireshark或charlesproxy比较请求,你很快就会发现有什么不同。

标签: objective-c ios asihttprequest nsurlrequest


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-13
    • 1970-01-01
    • 2014-06-14
    • 2020-06-22
    • 2023-04-05
    • 2020-04-16
    相关资源
    最近更新 更多