How to send form data to an API - Windev 24

964 views Asked by At

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: screenshot

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

1

There are 1 answers

0
yasseros On BEST ANSWER

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