Computer Hope

Software => Computer programming => Topic started by: bobsklarservices on December 30, 2011, 03:31:31 AM

Title: Perform an HTTP/1.1 POST in VBScript
Post by: bobsklarservices on December 30, 2011, 03:31:31 AM
I have had the idea to make a "Chat Autofixer" for XSketch.com, and in order to do this, I basically flood the chat with a message consisting of [ ]. I want to make it distributable, for my XSketch friends, and source-viewable. I'd like to do this using VBScript. Unfortunately, the server running XSketch is using GWT with a POST to send messages, and I don't know how to execute a POST in VBS. I only need to post a string, and I know what URL to post to. Does anyone know the code required to perform such an action?

PS> This will also help in my VB.NET application coming soon that will use POST.
Title: Re: Perform an HTTP/1.1 POST in VBScript
Post by: Rob Pomeroy on December 31, 2011, 11:55:12 AM
Ugh.  I wouldn't use VBScript for this.  Any language that can use a cURL library is a better bet.  But if you're determined, you might find some inspiration here: http://www.motobit.com/tips/detpg_post-binary-data-url/
Title: Re: Perform an HTTP/1.1 POST in VBScript
Post by: BC_Programmer on December 31, 2011, 11:43:31 PM
Code: [Select]
'URL to open....
sUrl = "http://www.example.com/page.php"
'POST Request to send.
sRequest = "varname=value&varname=value"

HTTPPost sUrl, sRequest

Function HTTPPost(sUrl, sRequest)
  set oHTTP = CreateObject("Microsoft.XMLHTTP")
  oHTTP.open "POST", sUrl,false
  oHTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
  oHTTP.setRequestHeader "Content-Length", Len(sRequest)
  oHTTP.send sRequest
  HTTPPost = oHTTP.responseText
 End Function
Title: Re: Perform an HTTP/1.1 POST in VBScript
Post by: bobsklarservices on January 02, 2012, 07:28:23 PM
Thanks to everyone for your helpfulness. I am now able to do what I was desiring to do in the first place. I officially declare this topic solved!