我正在使用AFNetworking 2.1.0在我的iPad應用程序和我的服務器之間進行通信。AFNetworking 2.0:多部分POST時出錯503
我繼承AFHTTPSessionManager和使用沒有問題如下:
[self POST:kAPIPath
parameters:params
success:^(NSURLSessionDataTask *task, id responseObject) {
successBlock(responseObject[@"result"]);
}
failure:^(NSURLSessionDataTask *task, NSError *error) {
failureBlock(error);
}];
但是當我添加了多部分,我的服務器返回
request failure. error: Request failed: service indisponible (503)
所以這不起作用:
[self POST:kAPIPath
parameters:params
constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
[formData appendPartWithFileData:uploadFile
name:@"file"
fileName:@"photo.jpg"
mimeType:@"image/jpeg"];
}
success:^(NSURLSessionDataTask *task, id responseObject) {
successBlock(responseObject[@"result"]);
}
failure:^(NSURLSessionDataTask *task, NSError *error) {
failureBlock(error);
}];
但它也返回錯誤503,當我只是這樣做(沒有修改formData):
[self POST:kAPIPath
parameters:params
constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
}
success:^(NSURLSessionDataTask *task, id responseObject) {
successBlock(responseObject[@"result"]);
}
failure:^(NSURLSessionDataTask *task, NSError *error) {
failureBlock(error);
}];
或本(零爲塊):
[self POST:kAPIPath
parameters:params
constructingBodyWithBlock:nil
success:^(NSURLSessionDataTask *task, id responseObject) {
successBlock(responseObject[@"result"]);
}
failure:^(NSURLSessionDataTask *task, NSError *error) {
failureBlock(error);
}];
我看了很多帖子,但不明白的地方這可能從何而來。錯誤503意味着
503 Service Unavailable The server is currently unavailable (because it is overloaded or down for maintenance).[2] Generally, this is a temporary state. Sometimes, this can be permanent as well on test servers.
但是,如果我使用沒有multipart的POST,我沒有問題。有沒有人有一個想法,這可能來自哪裏?
非常感謝!
五百個系列錯誤在服務器端顯示出一個問題 –