ASIHTTPRequest 和 NSURLRequest 不同的结果

发布于 2024-12-04 02:30:33 字数 924 浏览 1 评论 0原文

我使用 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 发送简单的同步请求,但结果相同。可能是什么?

I send request to some url with ASIHTTPRequest, and always get strange response with different HTML body. If i make same request from browser or from NSURLRequest class, i get correct response with correct HTML body.

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

I also tryed to send simple synchronous request with ASIHTTPRequest, but result the same. What it could be?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

笙痞 2024-12-11 02:30:33

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

may be server have different logic for different request header

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文