vba 使用 HTTP Post 将数据从 excel 发送到服务器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6312780/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 13:26:30  来源:igfitidea点击:

Sending data from excel to Server using HTTP Post

sql-serverasp.net-mvcvbahttp-post

提问by user793468

How can I send data to Server from excel using HTTP Post?

如何使用 HTTP Post 从 excel 向服务器发送数据?

Lets say the URL is: http://testingHttpPost/

假设 URL 是:http://testingHttpPost/

And I want to send data from Cells A2 and B2. How would I get this done in VBA?

我想从单元格 A2 和 B2 发送数据。我将如何在 VBA 中完成这项工作?

Thanks in advance

提前致谢

回答by Tim Williams

Sub XMLPost()
Dim xmlhttp, sData As String

    With ActiveSheet
        sData = "x=" & URLencode(.Range("A2").Value) & _
                "&y=" & URLencode(.Range("B2").Value)
    End With

    Set xmlhttp = CreateObject("microsoft.xmlhttp")

    With xmlhttp
        .Open "POST", " http://testingHttpPost/", False
        .setrequestheader "Content-Type", "application/x-www-form-urlencoded"
        .send sData
        Debug.Print .responsetext
    End With
End Sub

For URLencode function see here: How can I URL encode a string in Excel VBA?

有关 URLencode 函数,请参见此处:如何在 Excel VBA 中对字符串进行 URL 编码?