post image and test using multipart, but it gave me error Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request ,i am not able to post please help thanks in advance
NSMutableDictionary* post_dict = [[NSMutableDictionary alloc] init];
[post_dict setObject:Name.text forKey:@"name"];
[post_dict setObject:ContactNameTF.text forKey:@"contactname"];
[post_dict setObject:EmailTf.text forKey:@"email"];
[post_dict setObject:PasswordTF.text forKey:@"password"];
[post_dict setObject:HouseNumberTF.text forKey:@"housenumber"];
[post_dict setObject:StreetTF.text forKey:@"street"];
[post_dict setObject:cityTF.text forKey:@"city"];
[post_dict setObject:POstcodeTF.text forKey:@"postalcode"];
[post_dict setObject:ContactNumberTF.text forKey:@"contact"];
//[post_dict setObject:self.theImage forKey:@"image_url"];
NSString *urlString = @"http://www.ofertas24.net/codegen/index.php/codegen/register_post";
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:urlString]];
[request setHTTPMethod:@"POST"];
NSMutableData *body = [NSMutableData data];
NSString *boundary = @"---------------------------14737809831466499882746641449";
NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundary];
[request addValue:contentType forHTTPHeaderField:@"Content-Type"];
// add the image form fields
[body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"image_url\"; filename=\"%@image.jpg\"\r\n",NameTF.text ] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"Content-Type: image/jpeg\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:self.theImage];
[body appendData:[[NSString stringWithFormat:@"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
// add the text form fields
for (id key in post_dict) {
NSLog(@"%@",key);
[body appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"%@\"\r\n\r\n", key] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithString:[post_dict objectForKey:key]] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[@"\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
}
// close the form
[body appendData:[[NSString stringWithFormat:@"--%@--\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
// set request body
[request setHTTPBody:body];
// send the request (submit the form) and get the response
NSOperationQueue *queue =[[NSOperationQueue alloc]init];
[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError)
{
NSString *result = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
if ([result isEqualToString:@"true"]) {
[self performSelectorOnMainThread:@selector(mainViewController) withObject:nil waitUntilDone:NO];
}
else {
NSLog(@"%@",[[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding]);
}
}];