Huachao / vscode-restclient

REST Client Extension for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=humao.rest-client
MIT License
5.3k stars 440 forks source link

Get Authorization Token using multipart/form-data #629

Open jcvpacheco opened 4 years ago

jcvpacheco commented 4 years ago

When i'm trying to get the authorization token using the following format, and is returning the following error: "IdentityServer4 ",

POST https://MYOAUTH/connect/token HTTP/1.1 Host: MYHOST Content-Type: multipart/form-data;boundary=------MyBoundary

--------MyBoundary Content-Disposition: form-data; name="client_id" MYCLIENT

--------MyBoundary Content-Disposition: form-data; name="client_secret" Content-Type: application/x-www-form-urlencoded URL_Encode(MYSECRET )

--------MyBoundary Content-Disposition: form-data; name="scope" MYSCOPE

--------MyBoundary Content-Disposition: form-data; name="grant_type" client_credentials

--------MyBoundary--

This is the right format to make this type of requests? Many Thanks.

Huachao commented 4 years ago

@jcvpacheco could you please provide more details about the error response? I found one strange thing is that the hostname in URL is not the same as the one in Host header.

jcvpacheco commented 4 years ago

Hi, thanks for the reply. With or without host define, is always returning this image

Huachao commented 4 years ago

@jcvpacheco can you work with other HTTP client tools like cURL, Postman?

ricmrodrigues commented 4 years ago

using "rest-client.formParamEncodingStrategy": "always", with Content-Type: application/x-www-form-urlencoded works

SamLino commented 3 years ago

I was having problems with multipart. In my case it just worked with a BlankLine before the value, and no BlankLine after.

Example:

POST https://MYOAUTH/connect/token HTTP/1.1 Host: MYHOST Content-Type: multipart/form-data;boundary=------MyBoundary

--------MyBoundary Content-Disposition: form-data; name="client_id"

MYCLIENT --------MyBoundary Content-Disposition: form-data; name="client_secret" Content-Type: application/x-www-form-urlencoded URL_Encode(MYSECRET )

--------MyBoundary Content-Disposition: form-data; name="scope"

MYSCOPE --------MyBoundary Content-Disposition: form-data; name="grant_type"

client_credentials --------MyBoundary--

bigois commented 2 years ago

@SamLino, not even all heroes wear cape!

I'm creating a REST client in ADVPL to consume an API that uses multipart/form-data, and your example saved my day. Thank you so much! 💚

image