使用Web HDFS REST客户端

时间:2016-02-18 06:55:12

标签: hadoop httpclient apache-httpclient-4.x webhdfs

我正在使用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?

1 个答案:

答案 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