我正在开发一个java程序,它会将我的整个垃圾文件中的文件发送到我的服务器,以便通过某个URL http://ServerUrl:portNumber/file
进行扫描,但我在我的eclipse编译器中收到此错误
The method setEntity(HttpEntity) in the type HttpEntityEnclosingRequestBase is not applicable for the arguments (InputStream).
是不是因为Java Inputstream不能与setEntity方法一起使用?我无法逐字节读取文件,因为该文件不仅包含文档文件,也可能包含.exe文件。
这是我的源代码
public class SentFile {
public static void main(String [] args) {
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost("http://192.168.0.25:8008/file");
File file = new File("testScanFile.txt");
InputStream is = new FileInputStream(file);
post.setEntity(is);
HttpResponse response = client.execute(post);
BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
String line = "";
while ((line = rd.readLine()) != null) {
System.out.println(line);
}
}
}