When i am trying to upload image to server(tomcat)it is showing an error 400 as shown below Response is Apache Tomcat/7.0.22 - Error report
HTTP Status 400 -
type Status report
message
description The request sent by the client was syntactically incorrect ().
Apache Tomcat/7.0.22
if i send null in the space of image i am getting response correctly, The code in the BB works fine can any one help me please stuck with this from past two days
Code for iOS
NSURL *url = [NSURL URLWithString:@"http://api.domain.com:8080/Saldos/api/saldos/subirFoto"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
UIImage *image = [UIImage imageNamed:@"backGb.png"];
NSMutableData *bodyData = [[NSMutableData alloc] init];// backGb.jpg
NSData *imageData = UIImagePNGRepresentation(image);
[bodyData appendData:[[NSString stringWithFormat:@"pic"] dataUsingEncoding:NSUTF8StringEncoding]];
NSString *str = [[NSString alloc] initWithData:imageData encoding:NSASCIIStringEncoding];
[bodyData appendData:UIImageJPEGRepresentation(image, 9)];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"content-type"];
[request setValue:@"text/html,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/jpeg,*/*;q=0.5" forHTTPHeaderField:@"Accept"];
[request setValue:@"backGb.png" forHTTPHeaderField:@"pic"];
[request setHTTPMethod:@"POST"];
[request setHTTPBody:bodyData];
NSURLConnection *connection = [NSURLConnection connectionWithRequest:request delegate:self];
Code in BB:
httpConnection = MakeUrl.returnUrl(url);
httpConnection.setRequestMethod(HttpConnection.POST);
httpConnection.setRequestProperty("Content-Type",
HttpProtocolConstants.CONTENT_TYPE_MULTIPART_FORM_DATA);
httpConnection.setRequestProperty("User-Agent","Mozilla/5.0 (X11; U; Linux "+ "i686; en-US; rv:1.8.1.6) Gecko/20061201 Firefox/2.0.0.6 (Ubuntu-feisty)");
httpConnection.setRequestProperty("Accept","text/html,application/xml,"+ "application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/jpg,*/*;q=0.5");
httpConnection.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
URLEncodedPostData _postData = new URLEncodedPostData("UTF-8",false);
_postData.append("pic", postData);
OutputStream os = httpConnection.openOutputStream();
os.write(_postData.getBytes());
os.flush();