bir*_*rdy 5 java post apache-commons apache-httpclient-4.x
我正在尝试使用POST文件HttpClient。但是,我无法访问实际的,File但我可以访问其InputStream。有没有办法我仍然可以发布文件?
到目前为止,这是我所做的:
public void sendFile (InputStream instream) {
HttpClient client = new HttpClient();
PostMethod method = new PostMethod("http://localhost:8080/myservice/testupload");
Part[] parts = new Part[] {
//new FilePart("myFile", file.getName(), file)
};
method.setRequestEntity(
new MultipartRequestEntity(parts, method.getParams()));
client.executeMethod(method);
}
Run Code Online (Sandbox Code Playgroud)
如您所见,FilePart需求文件但是我有InputStream。如何将输入流发布为文件?
| 归档时间: |
|
| 查看次数: |
2855 次 |
| 最近记录: |