I am using AFNetworking 2.1.0 to communicate between my iPad app and my server.
I subclass AFHTTPSessionManager and use the following without problem :
[self POST:kAPIPath
parameters:params
success:^(NSURLSessionDataTask *task, id responseObject) {
successBlock(responseObject[@"result"]);
}
failure:^(NSURLSessionDataTask *task, NSError *error) {
failureBlock(error);
}];
But when I add the multipart portion, my server returns
request failure. error: Request failed: service indisponible (503)
So this does not work :
[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);
}];
But it also returns error 503 when I just do this (nothing modifying the 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);
}];
or this (nil for the block):
[self POST:kAPIPath
parameters:params
constructingBodyWithBlock:nil
success:^(NSURLSessionDataTask *task, id responseObject) {
successBlock(responseObject[@"result"]);
}
failure:^(NSURLSessionDataTask *task, NSError *error) {
failureBlock(error);
}];
I read many posts, but can not understand where this can come from. The error 503 means
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.
But if I use the POST without the multipart, I have no problem. Does anyone have an idea where this could come from ?
Thank you very much !!!