【问题标题】:translate Postman post Request with Basic Auth to mingw64 curl and powershell On Windows 10在 Windows 10 上将 Postman post Request with Basic Auth 转换为 mingw64 curl 和 powershell
【发布时间】:2021-04-03 06:05:40
【问题描述】:

我想将 Postman 的 POST 请求测试翻译成 Windows 上的 curl!

注意:ipusernamepassword是对这个问题的说明!

从 Postman 那里消费,我得到 200 OK Code 很好!

但是,尝试从 cmd 使用 curl 是行不通的!

检查邮递员curl code

我正在尝试使用 Powershell

curl --location --request POST 'http://10.31.7.52/BdN_SMS_CXP/api/SendSMS' --header 'Authorization: Basic bWFyaWVsYTpZMFMkaSRfViZTLjQwNio=' --header 'Content-Type: application/json' --data-raw '{"ANI" : 3007209820}'

curl --location --request POST 'http://10.31.7.52/BdN_SMS_CXP/api/SendSMS' --header 'Authorization: Basic bWFyaWVsYTpZMFMkaSRfViZTLjQwNio=' --header 'Content-Type: application/json' --data-raw '{\"ANI\" : 3007209820}'

检查编码/解码没问题。

现在直接用用户名和密码,根据https://stackoverflow.com/a/27442239/811293

curl --location --request POST 'http://10.31.7.52/BdN_SMS_CXP/api/SendSMS' --user 'mariela:Y0S$i$_V&S.406*' --header 'Content-Type: application/json' --data-raw '{"ANI" : 3007209820}'

这是我的结果。

当我使用curlmingw64 7.71.1 version 时,命令被误解,因为我得到了407 errorAuthentication required。这不仅仅是 powershell problem 解决的 Remove-item alias:curl

我怀疑你应该转义一些字符,并使用双逗号 " 而不是单逗号 '

我应该对$_&.* 字符(如果我应该使用任何字符)有什么注意事项?

我应该如何在 powershell(或 mingw64 curl)中编写请求以使其工作?

【问题讨论】:

    标签: powershell curl windows-10 postman mingw-w64


    【解决方案1】:

    生成的命令不是 powershell curl 而是 cmd curl :

    你可以直接在cmd中使用,

    或者,如果你想使用 powershel,请将其用作:

    $command= "curl --location --request POST 'http://10.31.7.52/BdN_SMS_CXP/api/SendSMS' --header 'Authorization: Basic bWFyaWVsYTpZMFMkaSRfViZTLjQwNio=' --header 'Content-Type: application/json' --data-raw '{""ANI"" : 3007209820}'"
    
    cmd /c $command
    

    【讨论】:

      猜你喜欢
      • 2017-03-30
      • 1970-01-01
      • 2019-03-06
      • 1970-01-01
      • 2016-03-21
      • 1970-01-01
      • 2018-02-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多