【问题标题】:How to send form data to an API - Windev 24如何将表单数据发送到 API - Windev 24
【发布时间】:2020-09-28 06:19:08
【问题描述】:

我正在尝试在 Windev24 上构建一个简单的应用程序,但我找不到正确的代码来使用 post 方法将数据发送到我使用 Lumen 框架构建的 API。如果我通过 Postman 测试 API,一切正常。这里是 Postman 窗口的截图:

我试过这段代码:

//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

我可以正确连接到 API(如果错误参数被添加到请求中,我会收到我创建的错误消息),但由于我找不到加入所需参数的正确方法,我处于停下来。

我试图阅读文档并试图自己弄清楚,但我找不到这样做的方法。

这里有人可以帮帮我吗?

提前谢谢你

【问题讨论】:

    标签: forms rest post windev


    【解决方案1】:

    这很简单,您必须使用MaReq.ContentType = {YourContentType} 指定要发送到服务器的内容类型,然后使用MaReq.content = {YourContent} 指定内容,因此您的代码应如下所示:

    //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
    

    【讨论】:

      猜你喜欢
      • 2019-07-24
      • 1970-01-01
      • 2021-09-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-14
      • 1970-01-01
      • 2022-06-14
      相关资源
      最近更新 更多