В моем приложении я использую службы AFNetworking для Parse. Здесь я должен отправить изображение на сервер, поэтому, когда когда-либо пытался отправить изображение, я получаю ниже сообщение об ошибке в качестве ответа.Как отправить изображение с помощью AFNetworking?
Вот мой код:
NSString *urlString = [NSString stringWithFormat:@"http://www.xyz.com:8084/TappyokaCmsService/Service.svc"];
NSString *path=[NSString stringWithFormat:@"/InsertUserInfo?User_Name=%@&User_Pwd=%@&User_FName=%@&User_LName=%@&User_Mail=%@&User_Phno=%@&User_Address=%@&User_Dob=%@&Ic_No=%@&User_Active=%@&User_Questions=%@&User_Ans=%@&ImageUrl=%@&IsSocial=%@",@"skull",@"skull",@"skull",@"skull",@"skull",@"skull",@"skull",@"skull",@"skull",@"10001",@"skull",@"skull",@"",@"10001"];
AFHTTPClient *httpClient= [AFHTTPClient clientWithBaseURL:[NSURL URLWithString:urlString]]; [httpClient registerHTTPOperationClass:[AFJSONRequestOperation class]]; [AFJSONRequestOperation addAcceptableContentTypes:[NSSet setWithObject:@"text/html"]]; NSMutableURLRequest *request = [httpClient multipartFormRequestWithMethod:@"POST" path:path parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
[formData appendPartWithFileData:imageToUpload name:@"skull" fileName:@"skull.jpg" mimeType:@"image/jpg"];
}];
// You can add then the progressBlock and the completionBlock
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject)
{
NSDictionary *jsons = [NSJSONSerialization JSONObjectWithData:responseObject options:kNilOptions error:nil];
NSLog(@"response: %@",jsons);
}
failure:^(AFHTTPRequestOperation *operation, NSError *error)
{
if([operation.response statusCode] == 403)
{
NSLog(@"Upload Failed");
return;
}
NSLog(@"error: %@", [operation error]);
}];
[operation start];
И сообщение об ошибке:
Status code: 404, headers {
"Content-Length" = 1245;
"Content-Type" = "text/html";
Date = "Wed, 20 Nov 2013 15:04:17 GMT";
Server = "Microsoft-IIS/7.5";
"X-Powered-By" = "ASP.NET"
Можете ли вы объяснить чистую плз? – user2230971
@ user2230971 Я отредактировал свой ответ, но я не могу сказать это гораздо более четко, чем то, что у меня есть. – NinjaLikesCheez