請(qǐng)求失?。翰豢山邮艿膬?nèi)容類型:使用AFNetworking 2.0的text / html我正在嘗試AFNetworking的新版本2.0,我收到了上面的錯(cuò)誤。知道為什么會(huì)這樣嗎?這是我的代碼: NSURL *URL = [NSURL URLWithString:kJSONlink];
NSURLRequest *request = [NSURLRequest requestWithURL:URL];
AFHTTPRequestOperation *op = [[AFHTTPRequestOperation alloc] initWithRequest:request];
op.responseSerializer = [AFJSONResponseSerializer serializer];
[op setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"JSON: %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
[[NSOperationQueue mainQueue] addOperation:op];我正在使用Xcode 5.0。此外,這是錯(cuò)誤消息:Error: Error Domain=AFNetworkingErrorDomain Code=-1016 "Request failed: unacceptable content-type: text/html" UserInfo=0xda2e670 {NSErrorFailingURLKey=kJSONlink, AFNetworkingOperationFailingURLResponseErrorKey=<NSHTTPURLResponse: 0xda35180> { URL: kJSONlink } { status code: 200, headers {
Connection = "Keep-Alive";
"Content-Encoding" = gzip;
"Content-Length" = 2898;
"Content-Type" = "text/html";
Date = "Tue, 01 Oct 2013 10:59:45 GMT";
"Keep-Alive" = "timeout=5, max=100";
Server = Apache;
Vary = "Accept-Encoding";} }, NSLocalizedDescription=Request failed: unacceptable content-type: text/html}我只是使用kJSONlink隱藏了JSON。這應(yīng)該返回一個(gè)JSON。
3 回答

陪伴而非守候
TA貢獻(xiàn)1757條經(jīng)驗(yàn) 獲得超8個(gè)贊
這意味著您的服務(wù)器正在發(fā)送"text/html"
而不是已經(jīng)支持的類型。我的解決辦法是添加"text/html"
到acceptableContentTypes
在設(shè)置AFURLResponseSerialization
類。只需搜索“acceptableContentTypes”并@"text/html"
手動(dòng)添加到集合中。
當(dāng)然,理想的解決方案是更改從服務(wù)器發(fā)送的類型,但為此您將不得不與服務(wù)器團(tuán)隊(duì)交談。

慕村9548890
TA貢獻(xiàn)1884條經(jīng)驗(yàn) 獲得超4個(gè)贊
我將@jaytrixz的答案/評(píng)論更進(jìn)一步,并將“text / html”添加到現(xiàn)有的類型集中。這樣當(dāng)他們將它在服務(wù)器端修復(fù)為“application / json”或“text / json”時(shí),我聲稱它將無縫地工作。
manager.responseSerializer.acceptableContentTypes = [manager.responseSerializer.acceptableContentTypes setByAddingObject:@"text/html"];
- 3 回答
- 0 關(guān)注
- 745 瀏覽
添加回答
舉報(bào)
0/150
提交
取消