Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Simple HTTP Client with VBScript

1,068 views
Skip to first unread message

Chris Feltman

unread,
Sep 10, 2001, 4:18:56 PM9/10/01
to
The following script implements a simple HTTP client:

option explicit

dim buffer

dim sock
dim connected

set sock = createobject("mswinsock.winsock")
wscript.ConnectObject sock, "wsc_"
if not isObject(sock) then
wscript.echo "could not create socket"
wscript.exit
end if

connected = false

sock.Remotehost = "www.cnn.com"
sock.RemotePort = 80
sock.protocol = 0
wscript.echo "waiting for connection ..."

sock.connect

while not Connected
wscript.sleep 200
wend

dim sendcomplete
sendcomplete = false
wscript.echo "sending request..."

sock.SendData "GET / HTTP/1.0" & chr(10) & chr(10)

while not sendcomplete
wscript.sleep 200
wend


' wait until the server finishes
while not sock.state = 8
wscript.sleep 200
wend
sock.close
set sock = nothing

wscript.echo "saving page..."
wscript.echo buffer
dim fso
set fso = createobject("scripting.filesystemobject")
dim file
set file = fso.createtextfile("C:\temp\news.htm", true)
file.write buffer
file.close
set file = nothing
set fso = nothing
wscript.echo "saved page"


sub wsc_Connect
connected = true
wscript.echo "connected!"
end sub

sub wsc_sendcomplete
sendcomplete = true
wscript.echo "data sent"
end sub

sub wsc_dataarrival(bytestotal)
if bytestotal = 0 then exit sub
dim localbuffer
wscript.echo "got " & bytestotal & " bytes of data"
sock.getdata localbuffer, vbstring
buffer = buffer & localbuffer

end sub

-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
Check out our new Unlimited Server. No Download or Time Limits!
-----== Over 80,000 Newsgroups - 19 Different Servers! ==-----

Michael Harris (MVP)

unread,
Sep 10, 2001, 9:20:42 PM9/10/01
to
An even simpler VBScript HTTP client...

set http = createobject("msxml2.xmlhttp")
sURL = "http://www.microsoft.com/ms.htm"
http.open "GET",sURL,false
http.send
sHtml = http.responsetext
msgbox sHtml


and no "mswinsock.winsock" design time license required...

--

Michael Harris
Microsoft.MVP.Scripting
--
mik...@mvps.org
Please do not email questions - post them to the newsgroup instead.
--
"Chris Feltman" <c.fe...@stanleyassociates.com> wrote in message
news:3b9d229f$1...@goliath.newsgroups.com...

0 new messages