2017-02-22 7 views
-1

나는 보통 분당 내 끝점을 치기 위해 cUrl을 사용합니다. 그러나 클라이언트 구축에 관해 생각해야 할 단계가 아닙니다.cUrl to apache HttpClient

: 나는 분명히 그 등가에 전달해야,

HttpGet getRequest = new HttpGet(
     "http://localhost:8080/api/private/v1/endpoint/"); 

HttpResponse response = httpClient.execute(getRequest); 

이제

curl -u "adminaccount:adminpassword" http://localhost:8080/api/private/v1/endpoint/ 

나는 아래의 코드를 말할 수 있습니다 :

나는 일반적으로 내 엔드 포인트 다음과 같은 방법을 명중 어쨌든 .

. 어떤 아이디어?

+1

downvote로 가려면 적어도 코멘트를 남겨 두십시오. – Edward

+0

HttpClient 문서를 확인하십시오. https://hc.apache.org/httpcomponents-client-ga/examples.html – Jyr

+0

HTTP 인증 헤더 란 무엇이며 Google에서 HttpGet에 설정하는 방법은 무엇입니까? - 힌트 : 귀하의 경우에 그것은 기본 인증 스키마에 관한 것입니다 ... – Vadim

답변

0

당신의 HttpClient를 만들 :

CredentialsProvider credsProvider = new BasicCredentialsProvider(); 
     credsProvider.setCredentials(
       new AuthScope("localhost", 8080), 
       new UsernamePasswordCredentials("adminaccount", "adminpassword")); 
     CloseableHttpClient httpclient = HttpClients.custom() 
       .setDefaultCredentialsProvider(credsProvider) 
       .build(); 

을하지만 그래 대신 구글하라고 것에 대해 발끈 얻는, 그냥 구글 이동합니다. 예를 들어, "HttpClient authentication example"에 대한 인터넷 검색을 시작하십시오. 사이트의 규칙은 매우 명확합니다 - "숙제를 먼저하십시오"

+0

나는 실제로 google을 만들었지 만, curl -u가 작동하기 때문에 curl -u와 같지 않습니다.이 방법은 406의 http 응답을 반환합니다. – MickeyThreeSheds