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

1 Answer 1

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?

Sign up to request clarification or add additional context in comments.

2 Comments

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?
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.