我正在使用Web HDFS REST客户端,我可以上传.xml
& .q
个文件。
代码的有用部分 -
CloseableHttpClient httpclient = HttpClients.createDefault();
HttpPut httpPut = new HttpPut(urlString);
httpPut.setHeader("Accept", "application/xml");
httpPut.setHeader("Content-type", "application/xml");
CloseableHttpResponse response = httpclient.execute(httpPut);
我在上传.jar
时遇到问题。上传的文件已损坏。
我应该在“Content-type”和“”Accept“”中设置什么来上传jar?
答案 0 :(得分:1)
HttpPut httpPut = new HttpPut(urlString);
httpPut.setEntity(new StringEntity(readFile(fileName)));
httpPut.setHeader("Accept", "binary/octet-stream");
httpPut.setHeader("Content-type", "binary/octet-stream");
使用 binary/octet-stream
代替 application/xml
。