Tuesday, September 28, 2010

Sending a HTTP Request with VBA




a. Sending a HTTP Post Request


Dim result As String
Dim myURL As String, postData As String
Dim winHttpReq As Object
Set winHttpReq = CreateObject("WinHttp.WinHttpRequest.5.1")

myURL = "http://192.168.10.101:80/your_web_service"
postData = "parameter=hello¶meter2=hi"

winHttpReq.Open "POST", myURL, False
winHttpReq.SetRequestHeader "Content-Type", "application/x-www-form-urlencoded"
winHttpReq.Send (postData)

result = winHttpReq.responseText






b. Sending a HTTP Get Request


Dim result As String
Dim myURL As String
Dim winHttpReq As Object
Set winHttpReq = CreateObject("WinHttp.WinHttpRequest.5.1")

myURL = "http://192.168.10.101:80/your_web_service?parameter=hello¶meter2=hi"

winHttpReq.Open "GET", myURL, False
winHttpReq.Send

result = winHttpReq.responseText

4 comments:

Tony said...

What character are you using between the post variables?

Thanks

Bihan Rana said...

the symbol is & (and)

Suat ATAN said...

Turkish translate of your post:

http://blog.suatatan.com/2012/11/excel-vba-ile-web-sunucusuna-http.html

Thanks

hugamen said...

And what If what i want to send is an csv file? Do you have any idea how to make it?