| w3Sockets Examples |
Examples
Wrapper.asp
<SCRIPT LANGUAGE=JSCRIPT RUNAT=SERVER>
/* HTTPSocket by Joshua J Baker - josh@cobaltcreative.com Designed for the Socket.dll by Dimac */ function HTTPSocket_2(URL){ /* Define the main properties */ this.URL = URL; this.Port = 80; this.Method = "GET"; this.Protocol = "HTTP"; this.Headers = new Object(); this.FullContent = ""; this.Head = ""; this.Content = ""; this.SendBuffer = ""; this.StoreBuffer = ""; this.Version = "1.0"; this.TimeOut = 10000; /* Parse the URL */ URL = URL.split(":"); switch (URL.length) { case 3: & nbsp; this.Protocol = URL[0].toUpperCase (); this.Host = URL[1].indexOf("//")==0?URL[1].substring(2).split("/")[0]:URL [0]; ; this.Port = parseInt(URL[2]).toString (); this.Query = URL[2].substring (this.Port.length); &n bsp; break; case 2: & nbsp; this.Host = URL[1].indexOf("//")==0?URL[1].substring(2).split("/")[0]:URL [0]; ; this.Protocol = (URL[1].indexOf("//")==0?URL[0]:this.Protocol).toUpperCase (); this.Port = URL[1].indexOf("//")==0?this.Port:parseInt(URL[1]).toString (); this.Query = URL[1].indexOf("//")==0?URL[1].substring(2+this.Host.length): (URL[1].split("/").length>1?URL[1].substring (this.Port.length):"/"); &nb sp; break; case 1: & nbsp; this.Host = URL[0].split("/")[0] &nb sp; this.Query = URL[0].indexOf("/")<URL[0].length-1&&URL [0].indexOf("/")!=-1?URL[0].substring (this.Host.length):"/"; } this.AddHeader = function(Name, Value){ this.Headers[Name] = Value; } this.RemoveHeader = function(Name) { this.Headers[Name] = false; } this.Execute = function() { this.SendBuffer = this.Method + " " + this.Query + " " + this.Protocol + "/" + this.Version + "\n"; for (prop in this.Headers) &nb sp; this.SendBuffer += !this.Headers[prop]?"":prop + ": " + this.Headers[prop] + "\n"; this.SendBuffer += "\n"; var Socket = Server.CreateObject ("Socket.TCP"); Socket.TimeOut = this.TimeOut; &n bsp; Socket.Host = this.Host + ":" + this.Port; ; Socket.Open (); Socket.SendText (this.SendBuffer); &nb sp; Socket.WaitForDisconnect (); this.StoreBuffer = Socket.Buffer; & nbsp; Socket.Close (); var j = this.StoreBuffer.indexOf("\n\r\n"), k = this.StoreBuffer.indexOf ("\n\n"); this.Head = ((j < k && j > -1)||(j > -1 && k == -1))?this.StoreBuffer.substring(0, j - 1):((k < j && k > -1)||(k > -1 && j == -1))?this.StoreBuffer.substring(0, k):this.StoreBuffer; & nbsp; this.Content = ((j < k && j > -1)||(j > -1 && k == -1))?this.StoreBuffer.substring(j + 3):((k < j && k > -1)||(k > -1 && j == -1))?this.StoreBuffer.substring(k + 3):this.StoreBuffer; & nbsp; return this.Content; } } function HTTPSocket(URL){ /* For creating a HTTPSocket in VBScript */ return new HTTPSocket_2(URL); } Set Sock = HTTPSocket("www.hotbot.com") Sock.AddHeader "User-Agent", "My Browser" Output = Sock.Execute() </SCRIPT> |
|
|