In meinem Fall funktioniert der Code unter iOS8 einwandfrei, aber unter iOS 7 gibt es ein Problem. Es wird ein Fehler angezeigt
"Error Domain=com.alamofire.error.serialization.response Code=-1011
"Anfrage fehlgeschlagen: fehlerhafte Anfrage (400)"
UserInfo=0x19039c00
Server = Apache; } }, NSErrorFailingURLKey=http://xxx/api/abc/PostApi },
NSLocalizedDescription=Anfrage fehlgeschlagen: fehlerhafte Anfrage (400),
com.alamofire.serialization.response.error.data=
Dies ist mein Code, der ein Problem hat
`
Code: Select all
@property (strong, nonatomic) NSURLSessionUploadTask *postUploadTask;
__block int i=1;
AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
NSMutableURLRequest *request = [[AFHTTPRequestSerializer serializer] multipartFormRequestWithMethod:@"POST" URLString:urlString parameters:postParameters constructingBodyWithBlock:^(id formData) {
if (imageArray.count > 0) {
long dataLenght = 0.0;
for(UIImage *eachImage in imageArray)
{
NSData *imageData = UIImageJPEGRepresentation(eachImage, .5);
dataLenght = dataLenght + imageData.length;
[formData appendPartWithFileData:imageData name:[NSString stringWithFormat:@"image%d",i] fileName:[NSString stringWithFormat:@"image%d.jpg",i] mimeType:@"image/jpeg"];
i++;
}
}
} error:nil];
NSProgress *progress = nil;
self.postUploadTask = [manager uploadTaskWithStreamedRequest:request progress:&progress completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
[progress removeObserver:object forKeyPath:kProgressFractionCompleted context:kPostUpdateTypePostUpdate];
completionBlock(responseObject, error, task);
}];
[self.postUploadTask resume];`
Code: Select all
AFHTTPRequestOperationManager *manager = [[AFHTTPRequestOperationManager alloc] initWithBaseURL:[NSURL URLWithString:BASE_URL]];
AFHTTPRequestOperation *op = [manager POST:urlString parameters:postParameters constructingBodyWithBlock:^(id formData) {
if (imageArray.count > 0) {
long dataLenght = 0.0;
for(UIImage *eachImage in imageArray)
{
NSData *imageData = UIImageJPEGRepresentation(eachImage, .5);
dataLenght = dataLenght + imageData.length;
[formData appendPartWithFileData:imageData name:[NSString stringWithFormat:@"image%d",i] fileName:[NSString stringWithFormat:@"image%d.jpg",i] mimeType:@"image/jpeg"];
i++;
}
}
} success:^(AFHTTPRequestOperation *operation, id responseObject){
completionBlock(responseObject, nil, task);
[progress removeObserver:object forKeyPath:kProgressFractionCompleted context:kPostUpdateTypePostUpdate];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
completionBlock(operation, error, task);
}];
[op start];
Dies ähnelt dem Problem „Error Domain=com.alamofire.error.serialization.response Code=-1011 „Anfrage fehlgeschlagen: fehlerhafte Anfrage (400)“.
Bitte helfen Sie mir, wenn Sie eine Idee dazu haben. Vielen Dank im Voraus.
Mobile version