当我尝试将图像上传到服务器(tomcat)时,它显示错误400,如下所示 响应是Apache Tomcat / 7.0.22 - 错误报告
类型状态报告
消息
描述客户端发送的请求在语法上是不正确的()。
如果我在图像空间中发送null我得到了正确的响应,BB中的代码工作正常可以任何人帮助我请过去两天坚持这个
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];
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();