Reputation: 19
I'm trying to build a simple application on Windev24 and I can't find the right code to send data with a post method to an API I built with Lumen framework. If I test the API via Postman, everything works fine. Here a screenshot of Postman window:
I tried this code:
//MaReq est un restRequête
LaRéponse est un restRéponse
MaReq.URL="https://mywonderfulapi.ch/record"
//I need to find the way to join parameters here...
MaReq.Méthode=httpPost
LaRéponse=RESTEnvoie(MaReq)
SI ErreurDétectée ALORS
Erreur(HErreurInfo(hErrComplet))
SINON
info(LaRéponse.Contenu)
Info(UTF8VersChaîne(LaRéponse.Contenu))
rep = JSONVersVariant(LaRéponse.Contenu)
info(rep)
FIN
I can correctly connect to the API (I get the error message I created in case falses parameters were added to the request), but as I can't find the right way to join the needed parameters, I'm at a stop.
I tried to read the documentation and I tried to figure it out by myself but I couldn't find the way to do that.
Could anyone here help me, please?
Thank you in advance
Upvotes: 0
Views: 1149
Reputation: 939
It's Pretty simple you have to specifiy the type of content you want to send to the server by using MaReq.ContentType = {YourContentType}
, then the content by using MaReq.content = {YourContent}
, so your code should look like this :
//MaReq est un restRequête
LaRéponse est un restRéponse
MaReq.URL="https://mywonderfulapi.ch/record"
MaReq.ContentType = //yourContentType
MaReq.Content = // YourContent
MaReq.Méthode=httpPost
LaRéponse=RESTEnvoie(MaReq)
SI ErreurDétectée ALORS
Erreur(HErreurInfo(hErrComplet))
SINON
info(LaRéponse.Contenu)
Info(UTF8VersChaîne(LaRéponse.Contenu))
rep = JSONVersVariant(LaRéponse.Contenu)
info(rep)
FIN
Upvotes: 1