亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

請求失?。翰豢山邮艿膬热蓊愋停菏褂肁FNetworking 2.0的text / html

請求失?。翰豢山邮艿膬热蓊愋停菏褂肁FNetworking 2.0的text / html

MYYA 2019-08-29 17:44:55
請求失?。翰豢山邮艿膬热蓊愋停菏褂肁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"手動添加到集合中。

當然,理想的解決方案是更改從服務器發送的類型,但為此您將不得不與服務器團隊交談。


查看完整回答
反對 回復 2019-08-29
?
慕村9548890

TA貢獻1884條經驗 獲得超4個贊

我將@jaytrixz的答案/評論更進一步,并將“text / html”添加到現有的類型集中。這樣當他們將它在服務器端修復為“application / json”或“text / json”時,我聲稱它將無縫地工作。

  manager.responseSerializer.acceptableContentTypes = [manager.responseSerializer.acceptableContentTypes setByAddingObject:@"text/html"];
查看完整回答
反對 回復 2019-08-29
  • 3 回答
  • 0 關注
  • 762 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號