|
@@ -0,0 +1,33 @@
|
|
|
+import org.apache.http.HttpResponse;
|
|
|
+import org.apache.http.auth.AuthScope;
|
|
|
+import org.apache.http.auth.UsernamePasswordCredentials;
|
|
|
+import org.apache.http.client.CredentialsProvider;
|
|
|
+import org.apache.http.client.methods.HttpGet;
|
|
|
+import org.apache.http.impl.client.BasicCredentialsProvider;
|
|
|
+import org.apache.http.impl.client.CloseableHttpClient;
|
|
|
+import org.apache.http.impl.client.HttpClients;
|
|
|
+import org.apache.http.util.EntityUtils;
|
|
|
+
|
|
|
+import java.io.IOException;
|
|
|
+
|
|
|
+public class Geoserver {
|
|
|
+ public static void main(String[] args) {
|
|
|
+ String url = "http://192.168.60.2:8080/geoserver/rest/layers";
|
|
|
+ String username = "admin";
|
|
|
+ String password = "geoserver";
|
|
|
+
|
|
|
+ CredentialsProvider provider = new BasicCredentialsProvider();
|
|
|
+ provider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(username, password));
|
|
|
+
|
|
|
+ try {
|
|
|
+ CloseableHttpClient client = HttpClients.custom().setDefaultCredentialsProvider(provider).build();
|
|
|
+ HttpGet request = new HttpGet(url);
|
|
|
+ HttpResponse response = client.execute(request);
|
|
|
+ String responseBody = EntityUtils.toString(response.getEntity());
|
|
|
+
|
|
|
+ System.out.println("Response: " + responseBody);
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|