5
什么是Java中的等值以下的curl命令:“卷曲-F” 相当于Java
curl -X POST -F "[email protected]$File_PATH"
请求我想用Java来执行的是:
curl -X POST -F '[email protected]_path' http://localhost/files/
我尝试:
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(_URL);
File file = new File(PATH);
MultipartEntity mpEntity = new MultipartEntity();
ContentBody cbFile = new FileBody(file, "bin");
mpEntity.addPart("userfile", cbFile);
httpPost.setEntity(mpEntity);
HttpResponse response = httpClient.execute(httpPost);
InputStream instream = response.getEntity().getContent();
你的问题到底是什么?有一点mroe的代码会有帮助,例如'httpPost'是什么? –
我正在尝试使用java程序发送curl命令(已经是Linux终端命令)。我尝试过多部分,但我不需要上传或下载文件,而是远程存储库之间的转移。 – amine
那么,你的Java代码是不完整的。我们不知道为什么它不起作用。所以请张贴更多的代码(是的,我们都知道'curl'是......叹了口气)。例如。你不会调用任何post-method,所以上面的片段显然不能工作。您至少需要一个HttpURLConnection ... –