我有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"}'
我需要使用spring restTemplate发布请求,但我找不到如何使用-u
答案 0 :(得分:1)
发现它,它只是意味着使用基本身份验证,我应该将YOUR-SITE-ID-HERE:YOUR-SECRET-API-KEY-HERE
加密为Base64字符串并在Authorization
标题中使用它
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();