請求失?。翰豢山邮艿膬热蓊愋停菏褂肁FNetworking 2.0的text / html我正在嘗試AFNetworking的新版本2.0,我收到了上面的錯誤。知道為什么會這樣嗎?這是我的代碼: 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。此外,這是錯誤消息: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。這應該返回一個JSON。
3 回答
陪伴而非守候
TA貢獻1757條經驗 獲得超8個贊
這意味著您的服務器正在發送"text/html"而不是已經支持的類型。我的解決辦法是添加"text/html"到acceptableContentTypes在設置AFURLResponseSerialization類。只需搜索“acceptableContentTypes”并@"text/html"手動添加到集合中。
當然,理想的解決方案是更改從服務器發送的類型,但為此您將不得不與服務器團隊交談。
慕村9548890
TA貢獻1884條經驗 獲得超4個贊
我將@jaytrixz的答案/評論更進一步,并將“text / html”添加到現有的類型集中。這樣當他們將它在服務器端修復為“application / json”或“text / json”時,我聲稱它將無縫地工作。
manager.responseSerializer.acceptableContentTypes = [manager.responseSerializer.acceptableContentTypes setByAddingObject:@"text/html"];
- 3 回答
- 0 關注
- 762 瀏覽
添加回答
舉報
0/150
提交
取消
