java Apache HTTP客户端相当于CURL命令,用于配置shapefile
以下CURL命令的httpclient代码的等效代码是什么
curl -v -u username:password-XPUT -H "Content-type: text/plain" -d "E:/path_to_shapefile/shapefiles/" "http://172.16.17.86:9090/geoserver/rest/workspaces/IDIRA6/datastores/scenario2373/external.shp?configure=all"
CURL命令运行良好。我对httpclient的了解有限,但是,为了适应类似的代码,以下是我的尝试:
import org.apache.http.client.fluent.*; public class QuickStart { public static void main(String[] args) throws Exception { Executor executor = Executor.newInstance() .auth("username", "password") .authPreemptive("172.16.17.86:9090"); // Line below does not compile String response = executor.execute(Request.Put("E:/path_to_shapefile/shapefiles/" "http://172.16.17.86:9090/geoserver/rest/workspaces/IDIRA6/datastores/scenario2373/external.shp?configure=all")) .returnResponse() .toString(); System.out.println(response); } }
上面的代码没有编译,因为我不知道如何在与CURL命令相同的请求中对两个URL进行编码。如能修改上述代码或采用新方法,将不胜感激
提前谢谢
# 1 楼答案
谢谢你的回答。我用bodyString替换了bodyFile,效果很好