群晖nas官方upload API java代码调用demo
public static void main(String[] args) throws Exception {
CloseableHttpClient httpclient = HttpClients.createDefault();
try {
HttpPost httppost = new HttpPost("http://192.168.1.110:5000/webapi/entry.cgi?api=SYNO.FileStation.Upload&method=upload&version=2");
httppost.addHeader("Cookie","id=你自己的sid");
FileBody fileBody = new FileBody(new File("D:\\test.png"), ContentType.DEFAULT_BINARY, "test.png");
HttpEntity reqEntity = MultipartEntityBuilder.create()
.addPart("overwrite", new StringBody("false", ContentType.TEXT_PLAIN))
.addPart("path", new StringBody("/server", ContentType.TEXT_PLAIN))
.addPart("create_parents", new StringBody("true", ContentType.TEXT_PLAIN))
.addPart("filename", fileBody)
.setLaxMode()
.build();
httppost.setEntity(reqEntity);
System.out.println("executing request " + httppost.getRequestLine());
CloseableHttpResponse response = httpclient.execute(httppost);
try {
System.out.println("----------------------------------------");
System.out.println(response.getStatusLine());
HttpEntity resEntity = response.getEntity();
if (resEntity != null) {
System.out.println("Response content length: " + resEntity.getContentLength());
System.out.println(EntityUtils.toString(resEntity));
}
EntityUtils.consume(resEntity);
} finally {
response.close();
}
} finally {
httpclient.close();
}
}
正文到此结束
- 本文标签: Java Spring Boot Spring
- 本文链接: https://www.kxop.top/article/47
- 版权声明: 本文由王开心原创发布,转载请遵循《署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)》许可协议授权