i have cURL
curl -i https://thisIsValidUrl \
-X PUT \
-H "Content-Type: application/json" \
-u YOUR-SITE-ID-HERE:YOUR-SECRET-API-KEY-HERE \
-d '{"email":"customer@example.com","created_at":1361205308,"first_name":"Bob","plan":"basic"}'
i need to post a request using spring restTemplate, but i cannot find how to use the -u
found it , it is just means to use basic authentication, i should encrypt YOUR-SITE-ID-HERE:YOUR-SECRET-API-KEY-HERE
as Base64 String and use it in Authorization
header
MultiValueMap<String, String> headers = new LinkedMultiValueMap<String, String>();
RestTemplate restTemplate = new RestTemplate();
headers.add("Authorization", "Basic " + Base64String);
headers.add("Content-Type", "application/json");
.
.
.
HttpEntity<RaisEventRequest> request = new HttpEntity<RaisEventRequest>(RaisEventRequest, headers);
ResponseEntity<RaisEventResponse> responseEntity = restTemplate
.exchange(eventsURL, HttpMethod.POST, request, RaisEventResponse.class);
return responseEntity.getBody();