服务器端正在接收错误的内容类型(发送的旧报头)



由于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);
}];

根据您的回复,请设置您的经理的内容类型如下

manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"application/json"];

最新更新