vscode-restclient
vscode-restclient copied to clipboard
JSON body params not recognized
I have the following REST API to try in VS Code REST client. It returns the error "AADSTS900144: The request body must contain the following parameter: 'grant_type'" . I looks like the grant_type json element is not passed to the server. The same request works fine in Postman.
###======== HTTP request below =======
POST https://accounts.accesscontrol.windows.net/
{
"grant_type":"client_credentials",
"client_id":"
Same. Here is my workaround.
POST /tokens/OAuth/2 HTTP/1.1
Host: https://accounts.accesscontrol.windows.net
Content-Type: application/json
{
"grant_type":"client_credentials",
"client_id":"",
"client_secret":"",
"resource":""
}
@satyakvv
POST https://accounts.accesscontrol.windows.net//tokens/OAuth/2 HTTP/1.1
There is an extra / in your request URL, could you please try again after removing it?
@secsilm what's your problem when you use your original way?
@secsilm what's your problem when you use your original way?
Backend got empty request body. But now it worked using my original way. Maybe there were some mistakes.
Thanks.
i've been noticing a similar issue as well. i'm running a local server and the body is never sent along with the request.
example:
POST http://localhost:3001/x/y
Content-Type: "application/json"
{
"something": "else"
}
no body is received in the server.
edit: i've just noticed the issue 🤦♂️ application/json cannot be wrapped in quotes, so the header should be Content-Type: application/json
POST http://localhost/rest-php/api/post/create.php
Content-Type: application/json
{
"title": "first post",
"category_id": "1",
"body": "This is a sample post"
}
###
getting null content in server. "Notice: trying to get property 'title' of non-object"
After removing the new line next to POST, it worked properly.
POST http://localhost/rest-php/api/post/create.php
Content-Type: application/json
{
"title": "first post",
"category_id": "1",
"body": "This is a sample post"
}
###
I also added to server.js app.use(express.urlencoded({ extended: true })); now works as expected
Try adding this to server.js: app.use(express.json());
Try adding this to server.js: app.use(express.json());
Thanks, this was my issue, my server.js was missing this
I am also having this issue. Of note:
- I just migrated to a new M1-based MacBook (from an Intel-based MacBook)
- the POST was working fine on the old MacBook
- The post fails with 'Missing query'.... but I can right-click and 'Copy Request as cURL', paste it on the terminal, and it works fine.
POST https://api-us.securitycenter.windows.com/api/advancedqueries/run
Authorization: Bearer {{authDefender.response.body.access_token}}
Content-Type: application/json
Accept: application/json
Accept-Encoding: gzip
{ "Query":"DeviceInfo
| where DeviceName contains 'ahostname'
"}
Another note- it works fine if I remove the newlines in the string like this:
{ "Query":"DeviceInfo | where DeviceName contains 'ahostname'"}
Like I said, this POST was working just fine on my old MacBook, but on the new (M1) MacBook it will not accept the newlines within the json string.
Technically JSON with a newline would need to be escaped. I think the REST Client was doing that behind the scenes on the old one? And it IS working when copied as cURL (new lines are stripped). So...