Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/212.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 无法将文件附加到POST请求_Android_File_Http Post_Multipartentity - Fatal编程技术网

Android 无法将文件附加到POST请求

Android 无法将文件附加到POST请求,android,file,http-post,multipartentity,Android,File,Http Post,Multipartentity,我在发送POST请求文件时遇到问题。若文件名有括号,那个么服务器根本并没有接收到文件,否则服务器接收到的文件名是我插入的 我已经尝试使用 -截击库 -appach HttpTime不同版本 - 我也经历了同样的结果 这是我使用的代码 String fileName = "link[image]";//name of the parameter HttpContext localContext = new BasicHttpContext();

我在发送POST请求文件时遇到问题。若文件名有括号,那个么服务器根本并没有接收到文件,否则服务器接收到的文件名是我插入的

我已经尝试使用
-截击库
-appach HttpTime不同版本
-
我也经历了同样的结果

这是我使用的代码

       String fileName = "link[image]";//name of the parameter         
       HttpContext localContext = new BasicHttpContext();
       MultipartEntityBuilder builder = MultipartEntityBuilder.create();
       builder.setLaxMode();
       builder.setCharset(Charset.forName("UTF-8"));
       builder.addBinaryBody(fileName, image, ContentType.APPLICATION_OCTET_STREAM, image.getName());//image - it's a File
       HttpClient client = new DefaultHttpClient();
       HttpPost post = new HttpPost(URL);
       HttpEntity entity = builder.build();
       post.setEntity(entity);
       HttpResponse response = client.execute(post, localContext);
       HttpEntity httpEntity = response.getEntity();
       String result = EntityUtils.toString(httpEntity);
这样试试

String fileName = "link[image]";
        HttpContext localContext = new BasicHttpContext();
        MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
        entity.addPart("image", new FileBody(new File(fileName)),"image/jpg");
        HttpClient client = new DefaultHttpClient();
        HttpPost post = new HttpPost(URL);
        HttpEntity entity = builder.build();
        post.setEntity(entity);
        HttpResponse response = client.execute(post, localContext);
        HttpEntity httpEntity = response.getEntity();
        String result = EntityUtils.toString(httpEntity);

这行不通。MultipartEntity已被弃用,并且没有此类构造函数。图像-是文件类型的对象。filename—请求中文件参数的名称。