我需要通过安全的RESTful Web服务发送歌曲(mp3 / wav)文件和一些数据。我使用MultipartEntity来创建HttpPost请求。但是当我通过HttpClient执行它时,服务器会返回以下错误:
HTTP状态400-错误请求 类型:状态报告 消息:错误请求 客户端发送的请求在语法上不正确(错误请求)。
但是,如果我们从Web界面调用该服务,服务表现良好。请帮助解决问题。
这是代码:
HttpClient httpclient = new DefaultHttpClient();
HttpPost postRequest = new HttpPost();
try {
MultipartEntity reqEntity = new MultipartEntity();
reqEntity.addPart("email", new StringBody("test@testmail.com"));
reqEntity.addPart("password", new StringBody("123"));
reqEntity.addPart("title", new StringBody("My new song"));
reqEntity.addPart("musicData", new FileBody(new File(FilePath)));
// FIlePath is path to file and contains correct file location
postRequest.setEntity(reqEntity);
postRequest.setURI(new URI(ServiceURL));
HttpResponse response = httpclient.execute(postRequest);
} catch (URISyntaxException e) {
Log.e("URISyntaxException", e.toString());
}
我还为MultipartEntity包含了apache-mime4j、httpclient、httpcore和httpmime JAR文件。
这是服务的HTML页面快照。
email
、musicData
等名称的大小写是正确的吗? - pawelzieba