1

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

user793468
  • 4,898
  • 23
  • 81
  • 126

1 Answers1

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

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

Community
  • 1
  • 1
Tim Williams
  • 154,628
  • 8
  • 97
  • 125
  • Thanks! Tim In your above example, If I want to insert the data in a SQL Server DB. Using your above example of HTTP Post how could I insert the "x" and "y" data in Table "DataTable" in columns "X" and "Y" respectively? – user793468 Jun 14 '11 at 18:39
  • Sorry - I'm not that familiar with asp.net(mvc). Typically the values X and Y will show up in the request.form name-value collection. Once you have those you can use ADO to do the insert. That's about as much as I can offer. I suggest you post a more specific question on that, including what language you're using for your asp.net – Tim Williams Jun 14 '11 at 20:45