Android error : MultipartEntity , request sent by the client was syntactically incorrect

谁说胖子不能爱 提交于 2019-12-05 01:42:27
Kyle Clegg

Try removing the setURI method and passing the URL in when you create your HttpPost object, as follows. This worked for me (more here).

HttpClient httpclient = new DefaultHttpClient();
HttpPost postRequest = new HttpPost(ServiceURL);
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)));     
    postRequest.setEntity(reqEntity);

    HttpResponse response = httpclient.execute(postRequest);

} catch (URISyntaxException e) {
    Log.e("URISyntaxException", e.toString());
} 
dilix

It seems header of the request is incorrect, this problem can occur if you use a different Auth protocol or upper/lower case or simply wrong things in header that server side can't handle.

Dont waste your time by trying different different combinations.There are some HTTP Request tools available for HTTP with which you can track request and response you are getting.Ex. HTTP Analyzer download trial version

Call URL from your working webinterface , copy request and response then do same with from program the tool is enogh capable to capture your request and response data.

Now compare working and non working request you will surely able to dignose the issue whether it can be header issue or some authentication related issue.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!