ASIHTTPRequest返回HTML而不是JSON [英] ASIHTTPRequest Returning HTML instead of JSON

查看:158
本文介绍了ASIHTTPRequest返回HTML而不是JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用ASIHTTPRequest来联系API,问题是它返回的是html而不是JSON,我不知道为什么.几周来一切都运转良好,我似乎无法弄清什么地方坏了.

I am using ASIHTTPRequest to contact an API the problem is that it is returning html instead of JSON and i have no idea why. Everything has been working great for weeks and i can't seem to figure out what has broken..

奇怪的是,使用浏览器或postie执行完全相同的请求会返回正确的JSON响应,但是当我通过ASIHTTPRequest进行请求时,这些响应头就是我得到的:

What's strange is doing exactly the same request with a browser or postie returns the correct JSON response, but when i do the request via ASIHTTPRequest these are the response headers i get:

"Cache-Control" = "private, max-age=0, must-revalidate";
    Connection = "keep-alive";
    "Content-Encoding" = gzip;
    "Content-Type" = "text/html; charset=utf-8";
    Date = "Tue, 05 Jul 2011 21:11:10 GMT";
    Etag = "\"e467792713ac4124f055c1719f4ea6c2\"";
    Server = "nginx/0.7.65";
    Status = "200 OK";
    "Transfer-Encoding" = Identity;
    "X-Runtime" = 1;

还有html(应该是json).

And the html (which should be json)..

<div id="universal_meta" logged_in_user_id="removed" style="display:none"></div>
<div id="meta" screen="projects" logged_in_as="removed"></div>
<h1>9 projects with 50 open issues</h1>
<ul class="biglinks progressbars">
 etc...

这是用于执行请求的代码.

Here is the code used to do the request..

NSURL *url = [NSURL URLWithString:path];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];

if(secure){
       [request setUsername:self.username];
       [request setPassword:self.password];
}

[request setDelegate:self];
[request setDidFinishSelector:@selector(requestDone:)];
[request setDidFailSelector:@selector(requestWentWrong:)];
[request setDownloadDestinationPath:destination];

[[self queue] addOperation:request]; //queue is an NSOperationQueue

我已对所有登录详细信息/URL进行了三重检查,所有内容都是正确的,由于我完全迷路,因此我非常感谢您提供任何帮助.

I have triple checked all of the login details/url, everything is correct, i would really appreciate any help with this one as i am completely lost.

-

更新:

Lighthouse已经承认存在与标题相关的错误.等待他们的解决方案.

Lighthouse have acknowledged a bug regarding headers on their side. Waiting on a solution from them.

推荐答案

您是否检查过使用浏览器发送的标题是否与通过代码发送请求时相同?

Did you check that the headers sent using your browser are also the same as when you send the request by code?

特别是您是否尝试将"Accept"标头添加到您的请求中以定义您接受JSON Content-Type?

Especially did you try to add the "Accept" header to your request to define that you accept the json Content-Type?

[request addRequestHeader:@"Accept" value:@"application/json"];

这篇关于ASIHTTPRequest返回HTML而不是JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆