AFNetworking读取json响应为text/html



我有两个项目,一个用于用户,另一个用于提供商。

我使用相同的代码和sam api的活动,它的工作很好,但它不为用户工作!!

我使用了这个代码

AFHTTPSessionManager *manager=[AFHTTPSessionManager manager];
NSString *strURL=[NSString stringWithFormat:@"%@%@",SERVICE_URL,path];
manager.requestSerializer = [AFHTTPRequestSerializer serializer];
manager.responseSerializer = [AFJSONResponseSerializer serializer];

,但错误是:

Error Error Domain=com.alamofire.error.serialization.response Code=-1011 "Request failed: forbidden (403)" UserInfo={NSLocalizedDescription=Request failed: forbidden (403), NSUnderlyingError=0x600002a08ba0 {Error Domain=com.alamofire.error.serialization.response Code=-1016 "Request failed: unacceptable content-type: text/html" UserInfo={NSLocalizedDescription=Request failed: unacceptable content-type: text/html, NSErrorFailingURLKey=https://api.com, com.alamofire.serialization.response.error.data={length = 3273, bytes = 0x3c21444f 43545950 45206874 6d6c3e0a ... 3c2f6874 6d6c3e0a }, com.alamofire.serialization.response.error.response=<NSHTTPURLResponse: 0x6000024d0b80> { URL: https://api.com } { Status Code: 403, Headers {
"Cache-Control" =     (
"private, max-age=0, no-store, no-cache, must-revalidate, post-check=0, pre-check=0"
);
"Content-Encoding" =     (
br
);
"Content-Type" =     (
"text/html; charset=UTF-8"
);
Date =     (
"Thu, 25 Feb 2021 07:26:49 GMT"
);
Expires =     (
"Thu, 01 Jan 1970 00:00:01 GMT"
);

我在代码中添加了这一行:

manager.responseSerializer.acceptableContentTypes = [manager.responseSerializer.acceptableContentTypes setByAddingObject:@"text/html"];

但是出现这个错误:

JSON文本没有以数组或对象开始,并允许未设置片段的选项。

然后,我添加了以下代码:

manager.responseSerializer = [AFJSONResponseSerializer
serializerWithReadingOptions:NSJSONReadingAllowFragments];

,它给了我同样的问题接受文本/html !!

请给我一个解决办法。

提前谢谢你。

已修复!!

我试图用下面的代码打印错误:

NSString* ErrorResponse = [[NSString alloc] initWithData:(NSData *)error.userInfo[AFNetworkingOperationFailingURLResponseDataErrorKey] encoding:NSUTF8StringEncoding];

NSLog(@"%@",ErrorResponse);

,错误是:Access denied | api.com used Cloudflare to restrict access

The owner of this website (api.com) has banned your access based on your browser's signature

服务器安全问题

相关内容

  • 没有找到相关文章

最新更新