更新时间:2022-06-27 05:54:41
我相信使用Java和 httpclient-4.x :
I believe this is more-or-less equivalent using Java and httpclient-4.x:
try {
Credentials credentials = new UsernamePasswordCredentials("admin", "password"); //-u admin:password
DefaultHttpClient httpClient = new DefaultHttpClient();
httpClient.getCredentialsProvider().setCredentials(AuthScope.ANY, credentials);
HttpPut put = new HttpPut("http://localhost:8080/my-server/file.ext"); //-X PUT
put.setEntity(new FileEntity(new File("/absolute/path/file/to/upload/file.ext"), "image/png")); //@ - absolute path
httpClient.execute(put);
} catch(Exception e) {
//-f, fail silently
}