AFNetworking预期的内容类型错误 [英] AFNetworking Expected content type error

查看:111
本文介绍了AFNetworking预期的内容类型错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在失败块中获取json字符串

I am getting the json string in failure block

 NSURL *url = [[NSURL alloc] initWithString:@"http://www.vinipost.com/Services/Update/UpdateService.asmx/GetPropSubType?"];
        NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url];
        [AFJSONRequestOperation addAcceptableContentTypes:[NSSet setWithObject:@"text/html"]];

        AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {

            NSLog(@"%@", JSON);
        } failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {
            NSLog(@"Request Failed with Error: %@, %@", error, error.userInfo);
        }];
        [operation start];

输出:

Request Failed with Error: Error Domain=AFNetworkingErrorDomain Code=-1016 "Expected content type {(
    "text/json",
    "text/javascript",
    "application/json",
    "text/html"
)}, got text/plain" UserInfo=0x71521a0 {NSLocalizedRecoverySuggestion=[{"PropTypId":1,"PropCatId":1,"PropTyp":"Flat/ Condo"}.......**


推荐答案

错误很明显:
Web服务返回错误的内容类型。
内容类型应为以下之一:

The error is clear: the web service is returning a wrong content type. The content type should be one of these:


text / json,
text / javascript ,
application / json,
text / html

"text/json", "text/javascript", "application/json", "text/html"

但它返回


text / plain

text/plain

此外,如果你看看http响应,它返回其中的HTML TAGS,因此AFNetworking无法解析。

Moreover, if you look at the http response, it returns HTML TAGS inside it, so AFNetworking is not able to parse.

如果此页:

http://www.vinipost.com/Services/Update/UpdateService.asmx/GetPropSubType?

在您的控制之下,纠正删除html标签和更改内容类型的行为

is under your control, correct the behavior removing html tags and changing the content type

这篇关于AFNetworking预期的内容类型错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆