Sending data from excel to Server using HTTP Post

别来无恙 提交于 2019-12-18 12:42:45

问题


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

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

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

Thanks in advance


回答1:


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?



来源:https://stackoverflow.com/questions/6312780/sending-data-from-excel-to-server-using-http-post

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!