Ios 使用http POST请求将图像上载到服务器

Ios 使用http POST请求将图像上载到服务器,ios,http,blackberry,httprequest,multipartform-data,Ios,Http,Blackberry,Httprequest,Multipartform Data,我试图上传图像到服务器,但它没有正确上传得到http错误415,当我试图上传在黑莓它是上传正确,有人能告诉我我错过了什么这里是BB和ios的代码 iOS的代码 NSData *imageData = UIImageJPEGRepresentation(img, 90); /// convert image in NSData NSString *urlString = @"http://api.Domain.com:8080/upImg/"; // your url NSString *cont

我试图上传图像到服务器,但它没有正确上传得到http错误415,当我试图上传在黑莓它是上传正确,有人能告诉我我错过了什么这里是BB和ios的代码

iOS的代码

NSData *imageData = UIImageJPEGRepresentation(img, 90); /// convert image in NSData
NSString *urlString = @"http://api.Domain.com:8080/upImg/"; // your url
NSString *contentType = [NSString stringWithFormat:@"multipart/form-data"];
 NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setHTTPMethod:@"POST"];
[request setValue:contentType forHTTPHeaderField: @"Content-Type"];
NSMutableData *postBody = [NSMutableData data];
[postBody appendData:[[NSString   stringWithFormat:@"pic"]dataUsingEncoding:NSUTF8StringEncoding ]];
[postBody appendData:[NSData dataWithData:imageData]];
[request setURL:[NSURL URLWithString:urlString]];
[request setHTTPBody:postBody];

// now lets make the connection to the web
 NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
 NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
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();

Mybe提供有关您的上下文的详细信息。我知道它在blackberry上,但请提供有关设置和连接设置的更多详细信息,以便更快地获得答案。黑莓代码工作正常,但iOS代码返回415错误?是的,这就是问题所在