为啥这个 API 在 AFNetworking 中将其响应作为“失败”返回,而它正是它应该是的并且状态码是 200?

Posted

技术标签:

【中文标题】为啥这个 API 在 AFNetworking 中将其响应作为“失败”返回,而它正是它应该是的并且状态码是 200?【英文标题】:Why does this API return its response in AFNetworking as a "failure", when it's exactly what it's supposed to be and the status code is 200?为什么这个 API 在 AFNetworking 中将其响应作为“失败”返回,而它正是它应该是的并且状态码是 200? 【发布时间】:2014-01-21 03:31:56 【问题描述】:

我将POST 公式化为一个名为 Diffbot 的 API,它会返回我想要的内容;一堆解析的文章。 (Here's how the API is interacted with.)

我使用以下代码执行此操作(删除我的令牌除外):

[AFDiffbotClient sharedClient].operationQueue.maxConcurrentOperationCount = NSOperationQueueDefaultMaxConcurrentOperationCount;
NSMutableArray *individualRequests = [[NSMutableArray alloc] init];

for (NSDictionary *URLAndID in URLsAndIDs) 
    NSString *articleURL = [URLAndID objectForKey:@"URL"];
    NSString *requestURL = [NSString stringWithFormat:@"/api/article?token=...&fields=text,title,url&fields=text,title,url&url=%@", articleURL];

    [individualRequests addObject:@@"method": @"GET",
                                    @"relative_url": requestURL];


NSError *error;
NSData *individualRequestsJSONData = [NSJSONSerialization dataWithJSONObject:individualRequests options:kNilOptions error:&error];
NSString *individualRequestsJSONString = [[NSString alloc] initWithData:individualRequestsJSONData encoding:NSUTF8StringEncoding];

NSDictionary *parameters = @@"token": @"...",
                             @"batch": individualRequestsJSONString;

[[AFDiffbotClient sharedClient] setParameterEncoding:AFFormURLParameterEncoding];
[[AFDiffbotClient sharedClient] postPath:@"http://diffbot.com/api/batch" parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) 
    NSLog(@"WIN");
 failure:^(AFHTTPRequestOperation *operation, NSError *error) 
    NSLog(@"%@", error);
];

这是我收到的部分回复 (full response on GitHub):

Error Domain=AFNetworkingErrorDomain Code=-1016 "Expected content type (
    "text/json",
    "application/json",
    "text/javascript"
), got text/plain" UserInfo=0xc0a43b0 NSLocalizedRecoverySuggestion=[
"headers":["name":null,"value":"HTTP/1.1 200 OK","name":"Transfer-Encoding","value":"chunked","name":"Vary","value":"Accept-Encoding","name":"Date","value":"Tue, 21 Jan 2014 02:42:38 GMT","name":"Content-Type","value":"application/json","name":"Server","value":"Apache-Coyote/1.1"],"body":"\"category\":\"business_finance\",\"title\":\"A Firsthand Account of Microsoft\\u2019s Employee-Ranking System\",\"text\":\"There were seven or eight of us managers in the conference room, all peers, as well as our own manager. The conference rooms all had large tables, whether heavy varnished oak or cheap plywood. The chairs were the sort that let you lean back with increasing tension, and they had a few levers underneath the seat that raise and lower the seat and adjust the back. I\\u2019m a fidgeter, so I played with them a lot during meetings.\\nWe were mostly white, and all men. Each of us had between three and six \\u201Cdirect reports\\u201D: nonmanager programmers who we oversaw. We were the direct reports of our manager. There were lots and lots of managers at Microsoft\\u2014it was the only path to advancement, so the company structure became more and more steeply vertical. Once or twice a year, we would all get together and decide how good each of our reports was, by ordering them from best to worst.\\nThe system was called the stack rank.\\nFollowing Friday\\u2019s news of Microsoft CEO Steve Ballmer\\u2019s imminent retirement, postmortems of his lackluster 13-year reign have pointed to stack ranking \\u2014which, to be entirely fair, predated him\\u2014as both a cause and a symptom of the corporation\\u2019s decline. As a software developer and later development lead at Microsoft between 1998\\u20132003, I had to evaluate others and be evaluated myself under this system. And I can say that yes, stack ranking is as toxic for innovation and integrity and morale as media reports made it out to be , and then some.\\nEach report\\u2019s name was written on an index card and put on the table. It was a two-step process. First, reports were broadly sorted into four buckets: excellent, good, mediocre, and awful. Then, within each bucket, people were paired for comparison and bubbled up or down. Managers would argue whether a particular report was better or worse than some other manager\\u2019s report in the same bucket. Our manager would adjudicate the debates. Some managers were better fighters than others.\\nA manager\\u2019s goals here are twofold. First, you want to place your best people as high as possible on the ladder. This will help them get big bonuses, promotions, and raises, and thus keep them happy and less likely to leave your group or the company. Second, if you\\u2019re unfortunate enough to have weak reports, you want either to help them by placing them sufficiently high that they don\\u2019t get dinged too badly come the annual review, or to throw them to the wolves and let them get ranked low. If you give up on them, they\\u2019ll be put on a dead-end track that marks them as more or less useless. The object is to get them out from under you and make them someone else\\u2019s problem.\\nI was lucky not to have any weak reports. I had been encouraged to take one at an earlier point, but frenetically talked my way out of it, using all the managerese I could summon to argue that he didn\\u2019t belong on my team.\\nMy reports seemingly did fine. I got them all into the top two buckets. After the stack rank was over, our boss, who\\u2019d overseen the whole meeting, took our stack rank and then went to another, similar meeting one level up, where now we would be stacked and ranked behind our backs, then mixed in with the stack we\\u2019d just created, cruelly shuffled like a deck of human cards.\\nEventually, the vice presidents would have to bargain among themselves for how many bonuses and raises they would get for their entire organizations, then ration them out according to the stack rank. People would then be assigned one of three grades: 4.0 (Above Average), 3.5 (Average), and 3.0 (Below Average). The very rare 4.5 got you a set of steak knives ; a 2.5 meant you were fired (more or less). I\\u2019m not sure if Alan Turing himself could have gotten a 5.0.\\nThe stack rank was harmful. It served as an incentive not to join high-quality groups, because you\\u2019d be that much more likely to fall low in the stack rank. Better to join a weak group where you\\u2019d be the star, and then coast. Maybe the executives thought this would help strong people lift up weak teams. It never worked that way. More often, it just encouraged people to backstab their co-workers, since their loss entailed your profit.\\nThe stack rank was a zero-sum game\\u2014one person could only excel by the amount that others were penalized. And it was applied at every level of the organization. Even if you were in a group of three high performers, it was very likely that one of you would be graded Above Average, one Average, and one Below Average. Unless your manager was a prick or an idiot or both, the ordering would reflect your relative skills, but that never came as too much comfort to the hard-working schlub who just wasn\\u2019t as good as the other two.\\nThis was my problem. I had three reports, A, B, and C, and they neatly fit into three categories: C was good, B was great, and A was fantastic. They were all nice and retiring sorts\\u2014they weren\\u2019t self-promoters, which put them at a disadvantage at Microsoft\\u2014and I did want to do well by them. Based on their position in the stack rank, I thought that this would have been a fair assessment of them relative to the company in general:\\nMy Ideal Distribution\\nA: Above Average\\nB: Above Average\\nC: Average\\nAbove Average would get A and B nice bonuses and raises, while C might get a small raise and a decent bonus with an Average. That didn\\u2019t happen. My manager told me baldly that this was how it would go:\\nThe Actual Distribution\\nA: Above average\\nB: Average\\nC: Below average\\nMy desired rankings were out of the question, since my manager would then have had to steal that extra Above Average from some other manager. I thought that B could live with Average (we were all well-compensated, after all), but rating C as Below Average hurt.\\nSo I argued for C, and my manager said there was exactly one alternative:\\nThe Alternative Distribution\\nA: Average\\nB: Average\\nC: Average\\nBut A had been at the very top of the stack! How could A do worse than people we\\u2019d all agreed were weaker programmers? I gave up and let C take the Below Average. This is the zero-sum game at work.\\nI still feel bad about this.\\nThen I had to explain things to my reports. This illustrated another problem with the system: It destroyed trust between individual contributors and management, because the stack rank required that all lower-level managers systematically lie to their reports. Why? Because for years Microsoft did not admit the existence of the stack rank to nonmanagers . Knowledge of the process gradually leaked out, becoming a recurrent complaint on the much-loathed (by Microsoft) Mini-Microsoft blog , where a high-up Microsoft manager bitterly complained about organizational dysfunction and was joined in by a chorus of hundreds of employees. The stack rank finally made it into a Vanity Fair article in 2012, but for many years it was not common knowledge, inside or outside Microsoft. It was presented to the individual contributors as a system of objective assessment of \\u201Ccore competencies,\\u201D with each person being judged in isolation.\\nWhen review time came, and programmers would fill out a short self-assessment talking about their achievements, strengths, and weaknesses, only some of them knew that their ratings had been more or less already foreordained at the stack rank. The ones who knew could sometimes be recognized by their flip comments on their performance reviews, like the hot-tempered guy who wrote every year in \\u201CAreas to Improve,\\u201D \\u201CI will try to be less of an asshole.\\u201D\\nThey were exceptions, though. If you did know about the stack rank, you weren\\u2019t supposed to admit it. So you went through the pageantry of the performance review anyway, arguing with your manager in the rhetoric of \\u201Ccore competencies.\\u201D The managers would respond in kind. Since the managers had little control over the actual score and attendant bonus and raise (if any), their job was to write a review to justify the stack rank in the language of absolute merit. (\\u201CHigher visibility\\u201D was always a good catch-all: Sure, you may be a great coder and work 80 hours a week, but not enough people have heard of you!)\\nStrangely, this charade would sometimes happen even between managers and their managers, both pretending that they didn\\u2019t know about the stack rank that they had recently participated in. This kind of bad faith is more common than you might think. I saw it most vividly in a certain number of party-liners who seemed wholly oblivious to the dissonance between the performance review and the stack rank, as though the two would always magically line up, even though they never did.\\nThis sort of organizational dissembling skews your psyche. After I left Microsoft, I was left with lingering paranoia for months, always wondering about the agendas of those around me, skeptical that what I was being told was the real story. I didn\\u2019t realize until the nonstacked performance review time at my new job that I\\u2019d become so wary. At the time\\u2014inside Microsoft\\u2014it just seemed the only logical way to be.\",\"date_created\":\"Mon, 20 Jan 2014 18:02:03 PST\",\"categories\":\"entertainment_culture\":0.014285714285714284,\"hospitality_recreation\":0.03428571428571428,\"other\":0.0,\"business_finance\":0.5157142857142857,\"technology_internet\":0.05999695366444171,\"socialissues\":0.022857142857142854,\"sports\":0.04052786085981821,\"humaninterest\":0.03714285714285714,\"religion_belief\":0.039999999999999994,\"war_conflict\":0.022259647554023695,\"education\":0.011428571428571427,\"health_medical_pharma\":0.031428571428571424,\"labor\":0.028571428571428567,\"law_crime\":0.023333333333333327,\"politics\":0.01714285714285714,\"environment\":0.039596490302668735,\"weather\":0.00857142857142857,\"disaster_accident\":0.052857142857142846,\"supertags\":[\"id\":501672,\"positions\":[[92,100],[155,162],[647,654],[684,692],[1795,1803],[1921,1928],[1964,1972]],\"scope\":\"baseball\",\"name\":\"Manager (baseball)\",\"score\":0.7,\"contentMatch\":0.47236180904522607,\"categories\":\"22299804\":\"Baseball strategy\",\"17908961\":\"Sports coaches\",\"846062\":\"Baseball managers\",\"2280640\":\"Baseball coaches\",\"9697509\":\"Baseball occupations\",\"type\":1,\"senseRank\":1,\"variety\":0.7574257425742574,\"depth\":0.6470588235294117,\"id\":337689,\"positions\":[[1950,1957]],\"name\":\"Debate\",\"score\":0.6,\"contentMatch\":0.8994974874371859,\"categories\":\"698270\":\"Debating\",\"type\":1,\"senseRank\":1,\"variety\":0.5891089108910892,\"depth\":0.6470588235294117,\"id\":4692150,\"positions\":[[632,639],[887,894],[1479,1486],[1626,1633],[1837,1843],[1890,1896],[2308,2315],[2717,2724],[2909,2916]],\"name\":\"Report\",\"score\":0.6,\"contentMatch\":0.7135678391959799,\"categories\":\"1222842\":\"Technical communication\",\"694072\":\"Documents\",\"type\":1,\"senseRank\":1,\"variety\":0.7623762376237624,\"depth\":0.7058823529411764,\"id\":30873450,\"positions\":[[12,19]],\"name\":\"Deposit account\",\"score\":0.6,\"contentMatch\":0.7135678391959799,\"categories\":\"38182585\":\"Banking terms\",\"type\":1,\"senseRank\":2,\"variety\":0.8415841584158416,\"depth\":0.6470588235294117],\"type\":\"article\",\"cid\":1350985132,\"url\":\"http:\\/\\/mobile.slate.com\\/articles\\/business\\/moneybox\\/2013\\/08\\/microsoft_ceo_steve_ballmer_retires_a_firsthand_account_of_the_company_s.single.html?original_referrer=http:\\/\\/t.co\\/yOO5N2OQxZ\"\n","method":"GET","code":200,"relative_url":"/api/article?token=...&fields=text,title,url&fields=text,title,url&url=http://mobile.slate.com/articles/business/moneybox/2013/08/microsoft_ceo_steve_ballmer_retires_a_firsthand_account_of_the_company_s.single.html?original_referrer=http%3A%2F%2Ft.co%2FyOO5N2OQxZ&utm_campaign=Buffer&utm_content=buffer47791&utm_medium=twitter&utm_source=buffer"
"headers":["name":null,"value":"HTTP/1.1 200 OK","name":"Vary","value":"Accept-Encoding","name":"Date","value":"Tue, 21 Jan 2014 02:43:46 GMT","name":"Content-Length","value":"7934","name":"Content-Type","value":"application/json","name":"Server","value":"Apache-Coyote/1.1"],"body":"\"icon\":\"http:\\/\\/cdn.macrumors.com\\/images-new\\/apple-touch-icon.png\",\"text\":\"Apple debuted a new television ad for the iPad during the NFL playoffs this weekend. The 90-second spot features a Robin Williams speech from the film Dead Poets Society overlaying the iPad being used in a variety of industries including filmmaking, mountaineering, SCUBA diving, music and more.\\nApple has also introduced a new website called \\\"Your Verse\\\" to share the stories of the iPad users behind the ad.\\nWe don\\u2019t read and write poetry because it\\u2019s cute. We read and write poetry because we are members of the human race. And the human race is filled with passion. And medicine, law, business, engineering \\u2014 these are noble pursuits and necessary to sustain life. But poetry, beauty, romance, love \\u2014 these are what we stay alive for.\\nTo quote from Whitman,\\n\\\"O me, O life of the questions of these recurring.\\nOf the endless trains of the faithless. Of cities filled with the foolish. What good amid these, O me, O life?\\nAnswer: that you are here. That life exists and identity. That the powerful play goes on, and you may contribute a verse.\\\"\\n\\\"That the powerful play goes on, and you may contribute a verse.\\\"\\nWhat will your verse be? Apple is using the spot, along with it's previously existing 'Life on iPad' website , to show the wide variety of ways the iPad can be used in work and life. Back in October, alongside the iPad Air launch, Apple ran a 'Pencil' television spot that touted the iPad's usefulness in \\\"clas-s-rooms, boardrooms, expeditions\\\" and in space.\",\"date_created\":\"Sun, 12 Jan 2014 11:08:40 PST\",\"date\":\"Sun, 12 Jan 2014 18:48:00 GMT\",\"type\":\"article\",\"cid\":1331963972,\"human_language\":\"en\",\"url\":\"http:\\/\\/www.macrumors.com\\/2014\\/01\\/12\\/your-verse-ipad-ad\\/\",\"author\":\"Sunday January 12, 2014 10:48 am PST by Jordan Golson\",\"title\":\"Apple Debuts New Poetry-Themed 'Your Verse' iPad TV Ad\",\"html\":\"<div><div class=\\\"image_frame\\\"><img alt=\\\"Advertisement\\\" src=\\\"http:\\/\\/s0.2mdn.net\\/948853\\/Scion_10Series_FR-S_Brand_300x250.jpg\\\"><\\/img><div class=\\\"caption\\\">Advertisement<\\/div><\\/div><div><div>\\n\\t\\t\\t\\t\\t\\tApple debuted a new television ad for the iPad during the NFL playoffs this weekend. The 90-second spot features a Robin Williams speech from the film <a href=\\\"http:\\/\\/www.youtube.com\\/watch?v=aS1esgRV4Rc\\\">Dead Poets Society<\\/a> overlaying the iPad being used in a variety of industries including filmmaking, mountaineering, SCUBA diving, music and more.<br><br>\\nApple has also <a href=\\\"http:\\/\\/www.apple.com\\/your-verse\\/\\\">introduced a new website<\\/a> called &quot;Your Verse&quot; to share the stories of the iPad users behind the ad. <br><br><blockquote>We don&rsquo;t read and write poetry because it&rsquo;s cute. We read and write poetry because we are members of the human race. And the human race is filled with passion. And medicine, law, business, engineering &mdash; these are noble pursuits and necessary to sustain life. But poetry, beauty, romance, love &mdash; these are what we stay alive for.<br><br>\\nTo quote from Whitman,<br><br>\\n&quot;O me, O life of the questions of these recurring.<br>\\nOf the endless trains of the faithless. Of cities filled with the foolish. What good amid these, O me, O life?<br>\\nAnswer: that you are here. That life exists and identity. That the powerful play goes on, and you may contribute a verse.&quot;<br><br>\\n&quot;That the powerful play goes on, and you may contribute a verse.&quot;<br><br>\\nWhat will your verse be?<\\/blockquote>Apple is using the spot, along with it's previously existing <a href=\\\"http:\\/\\/www.apple.com\\/ipad\\/life-on-ipad\\/\\\">'Life on iPad' website<\\/a>, to show the wide variety of ways the iPad can be used in work and life. Back in October, alongside the iPad Air launch, Apple ran a <a href=\\\"http:\\/\\/www.macrumors.com\\/2013\\/10\\/23\\/apple-posts-ipad-air-introduction-life-on-ipad-and-pencil-tv-ad-videos\\/\\\">'Pencil' television spot<\\/a> that touted the iPad's usefulness in &quot;clas-s-rooms, boardrooms, expeditions&quot; and in space.\\n                                        <\\/div><\\/div><div class=\\\"image_frame\\\"><img alt=\\\"Advertisement\\\" src=\\\"http:\\/\\/s0.2mdn.net\\/viewad\\/1361549\\/FY14_Nissan_CPO_728x90_V2.jpg\\\"><\\/img><div class=\\\"caption\\\">Advertisement<\\/div><\\/div><\\/div>\",\"categories\":\"entertainment_culture\":0.03542857142857143,\"hospitality_recreation\":0.011428571428571429,\"other\":0.0,\"business_finance\":0.002857142857142857,\"technology_internet\":0.0890952380952381,\"socialissues\":0.022857142857142857,\"sports\":0.39933333333333326,\"humaninterest\":0.09185714285714286,\"religion_belief\":0.054285714285714284,\"war_conflict\":0.0,\"education\":0.005714285714285714,\"health_medical_pharma\":0.0619047619047619,\"labor\":0.02,\"law_crime\":0.1142384513306551,\"politics\":0.03142857142857143,\"environment\":0.022428215336011578,\"weather\":0.0,\"disaster_accident\":0.037142857142857144,\"supertags\":[\"id\":21211,\"positions\":[[114,117]],\"name\":\"National Football League\",\"score\":0.8,\"contentMatch\":0.9236111111111112,\"categories\":\"27603183\":\"American football leagues in the United States\",\"33170718\":\"Sports leagues established in 1920\",\"31480721\":\"1920 establishments in the United States\",\"841731\":\"National Football League\",\"30960960\":\"Cooperatives in the United States\",\"33866299\":\"Professional sports leagues in the United States\",\"type\":1,\"senseRank\":1,\"variety\":0.26771653543307083,\"depth\":0.5882352941176471,\"id\":2861,\"positions\":[[52,54],[87,89],[462,464]],\"name\":\"Advertising\",\"score\":0.7,\"contentMatch\":1,\"categories\":\"884913\":\"Advertising\",\"1232608\":\"Promotion and marketing communications\",\"999626\":\"Graphic design\",\"7406890\":\"Communication design\",\"718764\":\"Finance\",\"type\":1,\"senseRank\":2,\"variety\":0.2440944881889764,\"depth\":0.7058823529411764,\"id\":8221,\"positions\":[[207,211]],\"name\":\"Death\",\"score\":0.7,\"contentMatch\":0.9236111111111112,\"categories\":\"921954\":\"Death\",\"2389032\":\"Life\",\"3265614\":\"Demography\",\"37107764\":\"Senescence\",\"type\":1,\"senseRank\":1,\"variety\":0.2755905511811023,\"depth\":0.7647058823529411,\"id\":53242,\"positions\":[[171,185]],\"name\":\"Robin Williams\",\"score\":0.7,\"contentMatch\":0.6666666666666666,\"categories\":\"1005370\":\"1951 births\",\"8273176\":\"People from Oakland County, Michigan\",\"1027717\":\"Science fiction fans\",\"5179534\":\"American stand-up comedians\",\"5598416\":\"American Episcopalians\",\"36085024\":\"Detroit Country Day School alumni\",\"25909468\":\"Outstanding Performance by a Cast in a Motion Picture Screen Actors Guild Award winners\",\"2834619\":\"American film actors\",\"8330045\":\"People from Marin County, California\",\"2834699\":\"American television actors\",\"15947829\":\"Cecil B. DeMille Award Golden Globe winners\",\"21357091\":\"Actors from California\",\"38633811\":\"21st-century American actors\",\"4801090\":\"Audio book narrators\",\"8278761\":\"American impressionists (entertainers)\",\"36931540\":\"Grammy Award-winning artists\",\"38608301\":\"20th-century American actors\",\"26497101\":\"American people of German descent\",\"15947643\":\"Best Musical or Comedy Actor Golden Globe (television) winners\",\"2554933\":\"American voice actors\",\"10147153\":\"Juilliard School alumni\",\"15947615\":\"Best Musical or Comedy Actor Golden Globe (film) winners\",\"26294350\":\"Living People\",\"26502512\":\"American people of Scottish descent\",\"3190124\":\"American comedians\",\"6202968\":\"Best Supporting Actor Academy Award winners\",\"26498486\":\"American people of Irish descent\",\"38424647\":\"Outstanding Performance by a Male Actor in a Supporting Role Screen Actors Guild Award winners\",\"22128351\":\"Actors from Chicago, Illinois\",\"type\":1,\"senseRank\":1,\"variety\":0.5039370078740157,\"depth\":0.6470588235294117],\"media\":[\"link\":\"http:\\/\\/s0.2mdn.net\\/948853\\/Scion_10Series_FR-S_Brand_300x250.jpg\",\"primary\":\"true\",\"caption\":\"Advertisement\",\"type\":\"image\",\"link\":\"http:\\/\\/s0.2mdn.net\\/viewad\\/1361549\\/FY14_Nissan_CPO_728x90_V2.jpg\",\"caption\":\"Advertisement\",\"type\":\"image\"]\n","method":"GET","code":200,"relative_url":"/api/article?token=...&fields=text,title,url&fields=text,title,url&url=http://www.macrumors.com/2014/01/12/your-verse-ipad-ad/",

正如您在顶部看到的那样,它表明它返回了一个错误。然而......再往下一点,它会返回 API 应有的内容:一堆 JSON 对象。它甚至将它记录在我的 Diffbot 帐户中作为成功的 API 调用。

我知道它表示它希望传递 JSON,但是如果我将 AFFormURLParameterEncoding 更改为 AFJSONParameterEncoding 我就会得到这个:

Error Domain=AFNetworkingErrorDomain Code=-1011 "Expected status code in (200-299), got 401" UserInfo=0xc3f91e0 NSLocalizedRecoverySuggestion="error":"Not authorized API token.","errorCode":401, AFNetworkingOperationFailingURLRequestErrorKey=<NSMutableURLRequest: 0xc2d2bf0>  URL: http://diffbot.com/api/batch , NSErrorFailingURLKey=http://diffbot.com/api/batch, NSLocalizedDescription=Expected status code in (200-299), got 401, AFNetworkingOperationFailingURLResponseErrorKey=<NSHTTPURLResponse: 0xc0b2e10>  URL: http://diffbot.com/api/batch   status code: 401, headers 
    Connection = "keep-alive";
    "Content-Encoding" = gzip;
    "Content-Type" = "application/json;charset=UTF-8";
    Date = "Tue, 21 Jan 2014 02:55:06 GMT";
    Server = "nginx/1.3.4";
    "Transfer-Encoding" = Identity;
    Vary = "Accept-Encoding";
 

这是一个 AFNetworking 错误(不太可能,但我仍在使用 AFNetworking 1.0),还是我在做一些愚蠢的事情(更有可能)?

【问题讨论】:

【参考方案1】:

看来您并不孤单。您包含的第一个错误似乎是发送多个服务器响应,因此显示为“text/html”。

您可以尝试以下“hackish”解决方案并将“text/html”添加到您可接受的类型中。看看这是否有帮助:

https://***.com/a/12726827/1134576

您的第二个错误是 401 错误,其中“401 Unauthorized”表示存在凭据错误。

【讨论】:

以上是关于为啥这个 API 在 AFNetworking 中将其响应作为“失败”返回,而它正是它应该是的并且状态码是 200?的主要内容,如果未能解决你的问题,请参考以下文章

AFNetworking 3.0迁移指南

AFNetworking 3.0x版本最新特性

使用 AFNetworking 2.0 访问 DailyMile API

为啥我使用 AFNetworking 获得“内容长度”,而使用 Alamofire 却没有?

AFNetworking 3.0迁移指南

为啥在 AFNetworking 中使用点对点类型(NSProgress * __autoreleasing *)而不仅仅是点类型(NSProgress * __autoreleasing)?