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

时间:2011-06-10 22:44:32

标签: sql-server asp.net-mvc vba http-post

如何使用HTTP Post从Excel发送数据到服务器?

假设网址为:http://testingHttpPost/

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

提前致谢

1 个答案:

答案 0 :(得分:6)

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

对于URLencode功能,请参见此处:How can I URL encode a string in Excel VBA?