Apache HTTP 客户端相当于 CURL 命令来配置形状文件



以下CURL 命令的 httpclient 代码等效物是什么

curl -v -u 用户名:password-XPUT -H "内容类型:文本/纯文本" -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 static void main(String[] args) 抛出异常 {  Executor executor = Executor.newInstance() .auth("用户名"、"密码") .authPreemptive("172.16.17.86:9090"); 下面的行无法编译 字符串响应 = 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 进行编码。修复上述代码或采用新方法将不胜感激。

提前谢谢。

import org.apache.http.client.fluent.*;
import org.apache.http.entity.ContentType;
public class QuickStart {
public static void main(String[] args) throws Exception {  
Executor executor = Executor.newInstance()
.auth("admin", "geoserver")
.authPreemptive("172.16.17.86:9090");       
String response = executor.execute(Request.Put("http://172.16.17.86:9090/geoserver/rest/workspaces/IDIRA6/datastores/scenario2373/external.shp?configure=all")
.bodyString("E:\Tomcat\apache-tomcat-8.5.37\webapps\geoserver\data\data\IDIRA6\scenario2373\", ContentType.create("text/plain")))
.returnResponse()
.toString();
System.out.println(response);
}
}

谢谢你的回答。我用bodyString替换了bodyFile,这奏效了。

import org.apache.http.client.fluent.*;
import org.apache.http.entity.ContentType;
public class QuickStart {
public static void main(String[] args) throws Exception {  
Executor executor = Executor.newInstance()
.auth("admin", "geoserver")
.authPreemptive("172.16.17.86:9090");       
String response = executor.execute(Request.Put("http://172.16.17.86:9090/geoserver/rest/workspaces/IDIRA6/datastores/scenario2373/external.shp?configure=all")
.bodyString("E:\Tomcat\apache-tomcat-8.5.37\webapps\geoserver\data\data\IDIRA6\scenario2373\", ContentType.create("text/plain")))
.returnResponse()
.toString();
System.out.println(response);
}
}

最新更新