Всем привет. как правильно перенести запрос из curl в HttpClient или URL, точнее мне нужно авторизироваться (получить токен)
curl trusted-app:secret@localhost:8080/oauth/token -d "grant_type=password&username=user&password=password"
Через CUrl - все работет получаю токен в ответе, а через HttpClient получаю в ответе
{"timestamp":1518116152990,"status":401,"error":"Unauthorized","message":"Bad credentials","path":"/oauth/token"}
Пробовал вот так, как описано здесь, но вероятно что то напутал.
HttpClient httpClient = HttpClients.createDefault();
HttpUriRequest request1 = RequestBuilder.get("http://localhost:8080/oauth/token")
.addHeader("trusted-app", "secret")
.setEntity(new UrlEncodedFormEntity(Arrays.asList(
new BasicNameValuePair("grant_type", "password"),
new BasicNameValuePair("username", "user"),
new BasicNameValuePair("password", "password")
)))
.build();
HttpResponse response1 = httpClient.execute(request1);
Assert.assertEquals(HttpStatus.OK, response1.getStatusLine().getStatusCode());
Заранее благодарен за ответ!
"http://trusted-app:secret@localhost:8080/oauth/token"
.{"error":"method_not_allowed","error_description":"Request method 'GET' not supported"}