0
我试图做的是将数据作为字符串发送到我的外部服务器之一。但是在设置请求后,文件系统上的文件被损坏。使用HttpPost发送文件后文件被破坏
这里是我读我的文件转换成字符串
File file = new File("/some/path/on/my/hdd/testimg.png");
FileInputStream fis = new FileInputStream(file);
byte[] binaryData = new byte[(int) file.length()];
fis.read(binaryData);
String content = Base64.encodeBase64URLSafeString(binaryData);
fis.close();
这里是我该怎么办POST请求:
HttpClient client = HttpClientBuilder.create().build();
HttpPost request = new HttpPost("some.url");
... some headers ...
request.setEntity(new StringEntity(this.body)); // this.body is the String
HttpResponse response = client.execute(request); // HERE THE FILE GETS CORRUPTED
InputStream is = response.getEntity().getContent();
this.result = IOUtils.toString(is, "UTF-8");
谁能告诉我,为什么文件/some/path/on/my/hdd/testimg.png
在我的硬盘我发送请求后会被破坏?
感谢您的建议!
使用'Content-Type:image/png' ..... –
不起作用... – riedelinho