POST TOKEN

Posted by Giancarlo Alberto Somma on 27-Dec-2019 17:11

Hi,

I have to GET a TOKEN, 

Follow the parameters requested.

Link to request token
http://sage.brusapiastrelle.ch/token

Parameter to set headers
Content-Type    application/x-www-form-urlencoded

Parameter to set body
username          sage
password           ${>P3c72p=fyT5ZH
grant_type        password.
Its seems the code below is not correct (404 Not Found). Can you help Me? Thanks a lot.

BLOCK-LEVEL ON ERROR UNDO, THROW.

USING OpenEdge.Core.String.
USING OpenEdge.Net.HTTP.ClientBuilder.
USING OpenEdge.Net.HTTP.IHttpRequest.
USING OpenEdge.Net.HTTP.IHttpResponse.
USING OpenEdge.Net.HTTP.RequestBuilder.
USING Progress.Json.ObjectModel.JsonObject.

DEFINE VARIABLE httpUrl AS CHARACTER NO-UNDO.
DEFINE VARIABLE oRequest AS IHttpRequest NO-UNDO.
DEFINE VARIABLE oResponse AS IHttpResponse NO-UNDO.
DEFINE VARIABLE oRequestBody AS String NO-UNDO.
DEFINE VARIABLE oJsonEntity AS JsonObject NO-UNDO.
DEFINE VARIABLE JsonString AS LONGCHAR NO-UNDO.

SESSION:DEBUG-ALERT = TRUE.
httpUrl = "sage.brusapiastrelle.ch/token".

oRequestBody = new String('username=sage&password=$~{>P3c72p=fyT5ZH&grant_type=password').

oRequest = RequestBuilder:Post("sage.brusapiastrelle.ch/token", oRequestBody)
:ContentType('application/x-www-form-urlencoded')
:AcceptJson()
:Request.

oResponse = ClientBuilder:Build():Client:Execute(oRequest).

MESSAGE
oResponse:StatusCode SKIP
oResponse:StatusReason SKIP
VIEW-AS ALERT-BOX.

oJsonEntity = CAST(oResponse:Entity, JsonObject).
oJsonEntity:Write(JsonString, TRUE).

MESSAGE STRING(JsonString)
VIEW-AS ALERT-BOX.


 

All Replies

Posted by goo on 28-Dec-2019 13:56

Use fiddler to see what you Are sending, helped me big

Sendt fra min iPhone

27. des. 2019 kl. 18:14 skrev Giancarlo Alberto Somma <bounce-obonelinux@community.progress.com>:


<ProgressEmailLogo-png_2D00_150x42x2-png>
Update from Progress Community
<4U4AJMTEJRC6-jpg_2D00_70x70x2-jpg>
Giancarlo Alberto Somma

Hi,

I have to GET a TOKEN, 

Follow the parameters requested.

Link to request token
http://sage.brusapiastrelle.ch/token

Parameter to set headers
Content-Type    application/x-www-form-urlencoded

Parameter to set body
username          sage
password           ${>P3c72p=fyT5ZH
grant_type        password.
Its seems the code below is not correct (404 Not Found). Can you help Me? Thanks a lot.

BLOCK-LEVEL ON ERROR UNDO, THROW.

USING OpenEdge.Core.String.
USING OpenEdge.Net.HTTP.ClientBuilder.
USING OpenEdge.Net.HTTP.IHttpRequest.
USING OpenEdge.Net.HTTP.IHttpResponse.
USING OpenEdge.Net.HTTP.RequestBuilder.
USING Progress.Json.ObjectModel.JsonObject.

DEFINE VARIABLE httpUrl AS CHARACTER NO-UNDO.
DEFINE VARIABLE oRequest AS IHttpRequest NO-UNDO.
DEFINE VARIABLE oResponse AS IHttpResponse NO-UNDO.
DEFINE VARIABLE oRequestBody AS String NO-UNDO.
DEFINE VARIABLE oJsonEntity AS JsonObject NO-UNDO.
DEFINE VARIABLE JsonString AS LONGCHAR NO-UNDO.

SESSION:DEBUG-ALERT = TRUE.
httpUrl = "sage.brusapiastrelle.ch/token".

oRequestBody = new String('username=sage&password=$~{>P3c72p=fyT5ZH&grant_type=password').

oRequest = RequestBuilder:Post("sage.brusapiastrelle.ch/token", oRequestBody)
:ContentType('application/x-www-form-urlencoded')
:AcceptJson()
:Request.

oResponse = ClientBuilder:Build():Client:Execute(oRequest).

MESSAGE
oResponse:StatusCode SKIP
oResponse:StatusReason SKIP
VIEW-AS ALERT-BOX.

oJsonEntity = CAST(oResponse:Entity, JsonObject).
oJsonEntity:Write(JsonString, TRUE).

MESSAGE STRING(JsonString)
VIEW-AS ALERT-BOX.


 

View online

 

You received this notification because you subscribed to the forum.  To stop receiving updates from only this thread, go here.

Flag this post as spam/abuse.

Posted by Stefan Drissen on 30-Dec-2019 14:26

Can you get the token using Postman?

Posted by Giancarlo Alberto Somma on 30-Dec-2019 18:40

the code works fine. The problem was in the URL was wrong.

Thx.

Posted by Giancarlo Alberto Somma on 30-Dec-2019 18:40

the code works fine. The problem was in the URL was wrong.

Thx.

This thread is closed