VBScripting‎ > ‎

Query web service using form post (example 2)

Lots of different ways to query a web service:

Here's example of URL encoded form post

The script below returns the equivalent of submitting a FORM as follows:

<FORM ACTION=” http://localhost/test.asp” METHOD=”POST”>
<INPUT NAME=”field1” VALUE=”Kirby” />
The trick is that the Content-Type needs to be sent as a request header as follows. Each space needs to be encoded as a + character in the send() argument. Encode non-alphanumeric characters in the method using %XX encoding (for instance, the backslash is encoded as %5c).

Set objHTTP = CreateObject("Microsoft.XMLHTTP")
objHTTP.open "POST", "http://localhost/test.asp", False
objHTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
objHTTP.send "field1=kirby"
MsgBox objHTTP.responseText
Set objHTTP = Nothing