I am trying to make a POST request in java, and this is not working as expected.
Following this post, here is the code that I currently have
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(data, Consts.UTF_8);
What I can not understand, is that while debugging this, data
, is an ArrayList<NameValuePair>
which the debugger shows a value of
[Content-Type=text/json, Authorization=Bearer bZXL7hwy5vo7YnbiiGogKy6WTyCmioi8]
Which is completely expected, where I am at a complete loss, is that after this call, the value of entity is,
[Content-Type: application/x-www-form-urlencoded; charset=UTF-8,Content-Length: 78,Chunked: false]
The call has done absolutely nothing but ignore the data I passed it.
What have I done wrong here?
Edit
More Code
Caller
String authURL = "https://api.ecobee.com/1/thermostat";
authURL += "?format=json&body=" + getSelection();
// request headers
ArrayList<BasicNameValuePair> nvps = new ArrayList<BasicNameValuePair>();
nvps.add(new BasicNameValuePair("Content-Type", "text/json"));
nvps.add(new BasicNameValuePair("Authorization", "Bearer " + code));
// make the api call
String apiResponse = HttpUtils.makeRequest(RequestMethod.POST, authURL, nvps);
makeRequest method
public static String makeRequest(RequestMethod method, String url, ArrayList<BasicNameValuePair> data) {
try {
CloseableHttpClient httpClient = HttpClients.createDefault();
HttpRequestBase request = null;
switch (method) {
case POST:
// new post request
request = new HttpPost(url);
// encode the post data
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(data, Consts.UTF_8); // <-- this is where I have the issue
((HttpPost) request).setEntity(entity);
break;
...