EDIT: It looks like the main issue is setting a string-only header without key/value pairs and associated separators, since running a manual curl request with no "="s got me a server response, therefore I've edited the title.
I am trying to send a POST request to authenticate as described in this Amazon Alexa tutorial, from an Android app, using Volley.
For the second request I am sending (which requires a header), I receive a 400 server error, indicating a bad request.
According to the tutorial page, this is what the request header should look like:
The request must include the following headers:
POST /auth/o2/token Host: api.amazon.com Content-Type: application/x-www-form-urlencoded
If I use the regular getHeaders() method for the Volley Request class to override the headers, I can only set a hashmap, which results in the following header format:
{Host=api.amazon.com, Content-Type=application/x-www-form-urlencoded}
(or {POST=/auth/o2/token, Host=api.amazon.com, Content-Type=application/x-www-form-urlencoded}
if I include another line for the first bit)
Being new to Volley in general, I wonder if I'm missing something really obvious here. This is the request I am sending:
StringRequest tokenPoller = new StringRequest(
Request.Method.POST,
"https://api.amazon.com/auth/O2/token",
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.i("volley", response);
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
VolleyLog.d("volley", "Error: " + error.getMessage());
error.printStackTrace();
}
}) {
@Override
public String getBodyContentType() {
return "application/x-www-form-urlencoded";
}
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> params = new HashMap<String, String>();
params.put("grant_type", "device_code");
params.put("device_code", {{my device code from previous request}});
params.put("user_code", {{my user code from previous request}});
return params;
}
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String, String> headers = new HashMap<String, String>();
headers.put("Host", "api.amazon.com");
headers.put("Content-Type", "application/x-www-form-urlencoded");
return headers;
}
};
I suspect that something about the headers is off, but I really can't put my finger on it. I've tried not overriding the headers too, to no avail. Any pointers will be highly appreciated! Thanks!