Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to post a Image using AFNetworking?
    text
    copied!<p>In my app I am using AFNetworking to Parse services. Here I have to post a image to server, so when ever tried to post image I am getting below error message as response.</p> <p>Here is my code:</p> <pre><code>NSString *urlString = [NSString stringWithFormat:@"http://www.xyz.com:8084/TappyokaCmsService/Service.svc"]; NSString *path=[NSString stringWithFormat:@"/InsertUserInfo?User_Name=%@&amp;User_Pwd=%@&amp;User_FName=%@&amp;User_LName=%@&amp;User_Mail=%@&amp;User_Phno=%@&amp;User_Address=%@&amp;User_Dob=%@&amp;Ic_No=%@&amp;User_Active=%@&amp;User_Questions=%@&amp;User_Ans=%@&amp;ImageUrl=%@&amp;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&lt;AFMultipartFormData&gt; 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]; </code></pre> <p>And the error message is:</p> <pre><code>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" </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload