Viv*_*wat 6 iphone json objective-c ios afnetworking
我在失败块中获取json字符串
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];
Run Code Online (Sandbox Code Playgroud)
输出:
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"}.......**
Run Code Online (Sandbox Code Playgroud)
Sta*_*tan 10
您需要在操作前添加此行
[AFJSONRequestOperation addAcceptableContentTypes:
[NSSet setWithObject:@"text/plain"]];Run Code Online (Sandbox Code Playgroud)
错误很明显:Web服务返回错误的内容类型.内容类型应为以下之一:
"text/json","text/javascript","application/json","text/html"
但它回来了
纯文本/
此外,如果您查看http响应,它会在其中返回HTML TAGS,因此AFNetworking无法解析.
如果这个页面:
http://www.vinipost.com/Services/Update/UpdateService.asmx/GetPropSubType?
Run Code Online (Sandbox Code Playgroud)
在您的控制之下,纠正删除html标签和更改内容类型的行为
| 归档时间: |
|
| 查看次数: |
9612 次 |
| 最近记录: |