javeme commented on issue #1919:
URL: 
https://github.com/apache/incubator-hugegraph/issues/1919#issuecomment-1175764951

   看了下代码有一些问题,修改如下后再尝试下:
   ```java
   package com.baidu.hugegraph.example;
   
   import java.nio.charset.StandardCharsets;
   import java.util.Base64;
   
   import org.apache.http.HttpHeaders;
   import org.apache.http.HttpResponse;
   import org.apache.http.client.HttpClient;
   import org.apache.http.client.methods.HttpGet;
   import org.apache.http.impl.client.HttpClientBuilder;
   import org.apache.http.util.EntityUtils;
   
   public class TestHttpBasicAuth {
   
       private static final String HOST = "127.0.0.1:8080";
   
       public static void main(String[] args) throws Exception {
           String url = String.format("http://%s/graphs";, HOST);
           String user = "admin";
           String password = "pa";
   
           HttpClient client = HttpClientBuilder.create().build();
   
           HttpGet request = new HttpGet(url);
           // 手动构建验证信息
           String auth = user + ":" + password;
           byte[] encodedAuth = Base64.getEncoder().encode(
                                auth.getBytes(StandardCharsets.UTF_8));
           String authHeader = "Basic " + new String(encodedAuth);
           System.out.printf("Auth Header:\n  '%s: %s'\n",
                             HttpHeaders.AUTHORIZATION, authHeader);
           // 将验证信息放入到 Header
           request.setHeader(HttpHeaders.AUTHORIZATION, authHeader);
   
           HttpResponse response = client.execute(request);
           int status = response.getStatusLine().getStatusCode();
           String result = EntityUtils.toString(response.getEntity(),
                                                StandardCharsets.UTF_8);
           System.out.printf("Response(status %s) of '%s':\n  %s\n",
                             status, url, result);
       }
   }
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to