You need to configure basic authentication. For example, this works for me
with curl:

curl -u admin:admin http://localhost:6080/service/public/api/repository/1

Colm.

On Thu, Jun 16, 2016 at 10:35 AM, [email protected] <[email protected]> wrote:

>
> Hi, Ranger team!  I  recently study on ranger, and call ranger rest api
> by httpclient, but it failed!
> The following is mycode:
>
> public static void testGetRequest(String url) throws
> IllegalStateException, IOException {
> HttpClient client = new HttpClient();
> StringBuilder sb = new StringBuilder();
> InputStream ins = null;
> GetMethod method = new GetMethod(url);
> method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new
> DefaultHttpMethodRetryHandler(3, false));
> int statusCode = client.executeMethod(method);
> System.out.println("statusCode: " + statusCode);
> if (statusCode == HttpStatus.SC_OK) {
> ins = method.getResponseBodyAsStream();
> byte[] b = new byte[1024];
> int r_len = 0;
> while ((r_len = ins.read(b)) > 0) {
> sb.append(new String(b, 0, r_len, method.getResponseCharSet()));
> }
> }
> method.releaseConnection();
> if (ins != null) {
> ins.close();
> }
> }
>
>       public static void main(String[] args) throws Exception {
> String url = "http://10.133.47.146:6080/service/public/v2/api/policy/1";;
> testGetRequest(url);
> }
>
> Run the above program, the statusCode is 401!  Unauthorized !
> Could I add  any parameter when I call the rest api? How to resolve the
> problem? I hope you can describe how to call ranger rest api  on
> https://cwiki.apache.org/confluence/display/RANGER/Index .
>
> Thank you very much! Good Luck!
>
> Seymour Xu.
>
>


-- 
Colm O hEigeartaigh

Talend Community Coder
http://coders.talend.com

Reply via email to