Reputation: 503
I'm new to the Spring Rest API Library and networking, so any help I could receive would be greatly appreciated.
My understanding is that in HTTP networking, HTTP Request headers are that they can be used to specify what formats the client is willing to receive from the server as well as other specifications. In an app I am building, I need to set Request headers to an instance of Rest template (Using Spring Rest API) in order to connect to the server. I'm looking for examples on how to set specific HTTP Request headers to an instance of RestTemplate. I've been looking all over for examples of how to do it, and I can't find anything that can clearly explain it. Once again, any help would be appreciated.
Upvotes: 0
Views: 1401
Reputation: 853
Here is a code snippet on how to include parameters in headers.
public static HttpEntity<Object> createLMIHttpEntity(String username,
String password, String lastSyncDate, String pageSize,
String pageNumber) {
MultiValueMap<String, String> headers =
new LinkedMultiValueMap<String, String>();
headers.add("Accept", "application/json");
headers.add("userName", username);
headers.add("password", password);
headers.add("lastSyncDate", lastSyncDate);
headers.add("pageSize", pageSize);
headers.add("pageNumber", pageNumber);
return new HttpEntity<Object>(headers);
}
Then you can use it to execute the call like this:
ResponseEntity<String> response = restTemplate.exchange(url, httpMethod , requestEntity, String.class);
Let me know if you need more information.
Upvotes: 1