【发布时间】:2015-09-07 23:10:18
【问题描述】:
由于 64 位,我将 afnetwork 更新为 2.0。我一开始使用AFHTTPRequestSerializer时犯了一个错误,但是服务器端只接受Json。令人担忧的是,即使我使用了 AFHTTPRequestSerializer,它对我来说也能正常工作,所以我没有注意到这个问题并将错误应用程序发布给公众。然后我不断收到用户抱怨,不知何故我在我的设备上重建了我的应用程序,本地服务器可以捕获我错误的内容类型(应用程序/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);
}];
【问题讨论】:
-
我认为是头缓存问题,以前的用户一直发送旧头,有人知道如何更新缓存吗?
-
在我做了一些研究之后,我认为这个错误是由默认缓存策略引起的。现在我将策略添加为 NSURLRequestReloadIgnoringCacheData,希望它有效。
标签: ios json afnetworking afnetworking-2