我使用ASIHTTPRequest來聯繫API,問題是它返回的是HTML而不是JSON,我不知道爲什麼。一切都一直工作了好幾個星期,我似乎無法弄清楚什麼已經打破..ASIHTTPRequest返回HTML而不是JSON
奇怪的是做一個瀏覽器或postie完全相同的請求返回正確的JSON響應,但是當我做請求通過ASIHTTPRequest這些都是響應頭,我得到:
"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)..
<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...
這裏是用來做請求的代碼..
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
我已經三重檢查了所有的登錄細節/網址,一切正常,我真的很感謝任何幫助,因爲我完全失去了。
-
更新:
燈塔承認關於他們一邊頭的錯誤。等待他們的解決方案。
您可以使用某種客戶端工具作爲HTTPClient http://ditchnet.org/httpclient/來檢查您的服務器端是否一切正常 –