question

newuser-5edcae7f-b0c8-494b-9a62-d2b225db3ab6 avatar image

i post a request to get token return malformed request.

in my device , i connect to api.amazon.com . then i send a post request like alexa develop guide. it always return 400 error. and error descrption is malformed request, please help me to check it,

the code is below. it is the post string.

#define WEB_SERVER "api.amazon.com" 
#define WEB_PORT "443" 
#define WEB_URL "/auth/o2/token"
static const char *doss_get_token_req = "POST " WEB_URL " HTTP/1.1\n" "Host: "WEB_SERVER"\n"
    "Content-Type: application/x-www-form-urlencoded\n"
      "\n"
    "grant_type=authorization_code&code=ANvyBvruhFNZfcfgSzot&client_id=amzn1.application-oa2-client.c96ee94f933f4f86b10d4e85285bf9e3&client_secret=dd32c466d66319cb5f20d8230024d208e52116a2779f89b57f60dc225e052f02&redirect_uri=https%3A%2F%2Flyr.com\n"
        "\n";
alexa voice service
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

Hao@Amazon avatar image
Hao@Amazon answered

Hi,

Could you tell me which library you're using to send this HTTP request? Usually the library API should take care of setting the HTTP request headers, which means the POST, HTTP/1.1 field should not appear as part of you HTTP message body.

2 comments
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

i use tcp socket to sennd http request. not use lib .

0 Likes 0 ·
Sanjay@Amazon avatar image Sanjay@Amazon newuser-5edcae7f-b0c8-494b-9a62-d2b225db3ab6 ·

Can you verify that your request headers are properly formatted?

0 Likes 0 ·