由于64位,我将afnetwork更新为2.0。我首先使用AFHTTPRequestSerializer犯了一个错误,但服务器端只接受Json。对我来说,即使我使用AFHTTPRequestSerializer,它也能正常工作,所以我没有注意到这个问题并将错误应用程序公开发布。然后我一直收到用户抱怨,不知怎的,我在我的设备上重建我的应用程序,本地服务器可以捕获我错误的内容类型(application / x-www.form-urlencoded)。在我将AFHTTPRequestSerializer更新为AFJSONRequestSerializer后,它并没有解决问题,但用户仍然不断向服务器发送错误的内容类型,即使他们更新了应用程序。新用户没有问题,只发生在旧用户身上。
这与缓存问题有关吗?
服务器日志:
10:22:53 AM] Mark 1 contentType is: application/x-www-form-urlencoded, method is: POST headers are: Connection=keep-alive&Content-Length=1880739&Content-Type=application%2fx-www-form-urlencoded&Accept=*%2f*&Accept-Encoding=gzip%2c+deflate&Accept-Language=en%3bq%3d1&Cookie=ASP.NET_SessionId%3dbby5dlk5afmsnqnoqpprvqpw&Host
10:04:56 AM] contentType is: application/json, method is: POST header is: Connection=keep-alive&Content-Length=40352 4&Content-Type=application%2fjson &Accept=*%2f*&Accept-Encoding=gzip%2c+deflate&Accept-Language=en%3bq%3d1&Cookie=ASP.NET_SessionId%3dcw3gdkg3sff1f0j50z2rnism&Host
我的代码是
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.requestSerializer = [AFJSONRequestSerializer serializer];
manager.responseSerializer = [AFJSONResponseSerializer serializer];
AFHTTPRequestOperation *operation = [manager POST:_url parameters:requestParams success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"operation success: %@\n %@", operation, responseObject);
NSDictionary *decoded = [self processResponce:responseObject failureBlock:failureBlock];
if (!decoded) return;
BOOL containsError = [self checkErrorStatus:decoded failureBlock:failureBlock];
if (containsError) return;
successBlock(decoded[@"Data"]);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
failureBlock(FailureTypeUnknown, [error localizedDescription]);
}];
[operation setUploadProgressBlock:^(NSUInteger bytesWritten, long long totalBytesWritten, long long totalBytesExpectedToWrite) {
progressBlock(bytesWritten,totalBytesWritten,totalBytesExpectedToWrite);
}];
答案 0 :(得分:0)
根据您的回复,请将您的经理的内容类型设置如下
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"application/json"];