2017-09-14 50 views
1

我有捲曲春季發佈使用restTemplate請求與-u

curl -i https://thisIsValidUrl \ 
-X PUT \ 
-H "Content-Type: application/json" \ 
-u YOUR-SITE-ID-HERE:YOUR-SECRET-API-KEY-HERE \ 
-d '{"email":"[email protected]","created_at":1361205308,"first_name":"Bob","plan":"basic"}' 

,我需要用彈簧restTemplate發佈的請求,但我無法找到如何使用-u

回答

0

發現了它,它是隻是意味着使用基本身份驗證,我應該加密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(); 
+0

這並不追求提供了一個答案離子。要批評或要求作者澄清,請在其帖子下方留言。 - [來自評論](/ review/low-quality-posts/17331459) – horcrux