【问题标题】:How can I convert a Curl command into a WinHttpRequest object in vba excel如何在 vba excel 中将 Curl 命令转换为 WinHttpRequest 对象
【发布时间】:2020-07-12 14:20:53
【问题描述】:

给定一个 Curl 命令:

卷曲 https://URL
-u xxxxxxxxxxxxxxxxxxxxxx:
-X 发布
-F "source_file=@/tmp/my.doc"
-F "DoSomething=checkit"

预期的结果是一个 Json 字符串。 如何在 VBA Excel 宏中使用“WinHttp.WinHttpRequest.5.1”对象。 文件“my.doc”是按名称传输还是按字节数组传输?

我设法转换了一个简单的 Curl 命令:

卷曲 https://URL
-u xxxxxxxxxxxxxxxxxxxxxx:

下面的代码可以正常工作。

With CreateObject("WinHttp.WinHttpRequest.5.1")
    .Open "GET", URL, False
    .SetCredentials "xxxxxxxxxxxxxxxxxxxxxx", "", 0
    .send
    If .Status <> 200 Then
        If MsgBox(.responseText, vbOKOnly + vbCritical, "Error") = vbOK Then
            Exit Sub
        End If
    Else
        ss = .responseBody
        BodyData = StrConv(ss, vbUnicode)
        Set Json = JsonConverter.ParseJson(BodyData)
    End If

上面的 Curl 命令也是如此。 请帮忙。

【问题讨论】:

  • 我已尝试使用以下代码:

标签: excel vba curl winhttp


【解决方案1】:

您需要为 POST 请求修改和添加更多参数。尝试使用此示例进行调整,如果您遇到任何错误,请告诉我们。

POST request with win http

【讨论】:

  • 我尝试使用以下代码在 VBA Excel 中实现上述 Curl 代码:
猜你喜欢
  • 1970-01-01
  • 2020-07-09
  • 2021-10-08
  • 2016-10-24
  • 2020-10-21
  • 2015-08-23
  • 1970-01-01
  • 2019-06-04
  • 1970-01-01
相关资源
最近更新 更多