Logo
English Russian German French Spanish Italian
contact usprivacy
   Support Forums
chart
• About the product
• Download
• Sample projects:
Using with Visual Basic
Using with VB.NET
Using with C#
Using with ASP
Using with ASP.NET
Using with Office (VBA)
Using with VBScript
Using with JavaScript
Using with SQL Server
• Support Forum
OISV - Organization of Independent Software Vendors - Contributing Member
Winsock Component - Using with ASP

Using OstroSoft Winsock Component (OSWinsck.dll) in ASP form
Download sample script

Minimum requirements: IIS, OSWinsock.dll*
* If you don't have OstroSoft Winsock Component, see installation instructions

1. Make sure OstroSoft Winsock Component is installed and registered on your server
2. Create ASP file and enter the following code:

<%
Option Explicit
Dim wsTCP, sSource, sRequest, sPage, sServer, nPort, nConnected
sSource = "": sRequest = "": sPage = "": sServer = "": nPort = 80
nConnected = -1

On Error Resume Next
If Request.Form("Submit") = "View Source" Then
  sServer = Trim(Request.Form("URL"))
  If InStr(sServer, "://") > 0 Then _
    sServer = Mid(sServer, InStr(sServer, "://") + 3)
  If InStr(sServer, "/") > 1 Then
    sPage = Mid(sServer, InStr(sServer, "/"))
    sServer = Left(sServer, InStr(sServer, "/") - 1)
    If InStr(sPage, "#") > 1 Then _
      sPage = Left(sPage, InStr(sPage, "#") - 1)
  Else
    sPage = "/"
  End If
  If InStr(sServer, ":") > 1 Then
    nPort = Mid(sServer, InStr(sServer, ":") + 1)
    sServer = Left(sServer, InStr(sServer, ":") - 1)
  End If

  Set wsTCP = Server.CreateObject("OSWINSCK.TCP")
  If Request.Form("Proxy") <> "" Then
    sRequest = "GET http://" & sServer & sPage & " HTTP/1.0" & vbCrLf
    nConnected = wsTCP.Connect(CStr(Request.Form("Proxy")), 80)
  Else
    sRequest = "GET " & sPage & " HTTP/1.0" & vbCrLf
    nConnected = wsTCP.Connect(sServer, nPort)
  End If

  If nConnected = 0 Then
    'uncomment the next string if HTTP proxy fails to find the website
    'sRequest = sRequest & "Host: " & sServer & vbCrLf
    'sRequest = sRequest & "Proxy-Connection: Keep-Alive" & vbCrLf
    wsTCP.SendData sRequest & vbCrLf
    wsTCP.Sleep 1000 'increase for slow websites
    sSource = wsTCP.GetData
    sSource = Replace(sSource, "<", "<")
    wsTCP.Disconnect
  End If
  Set wsTCP = Nothing
End If
If Err.Number <> 0 Then sSource = "<font color=red>Error " & _
  Err.Number & ": " & Err.Description & "</font>"
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html><head>
  <title>ASP sample project for OstroSoft Winsock Component</title>
  <style>body, td, input {font-family: arial, verdana, helvetica, 
    sans-serif; font-size: 9pt;}</style>
</head>

<body>
<form action="oswinsck_asp.asp" method="post"><table>
<tr><td align=right>URL</td><td><input type="text" 
  name="URL" value="<%=Request.Form("URL")%>" size="60"></td></tr>
<tr><td align=right>HTTP Proxy</td><td><input type="text" 
  name="Proxy" value="<%=Request.Form("Proxy")%>" size="60"></td></tr>
<tr><td></td><td align=center><input type="submit" 
  name="submit" value="View Source"></td></tr>
</table><hr></form>
<pre><%=sSource%></pre>
</body></html>

Copyright © 1996-2010 OstroSoft. All rights reserved. info@ostrosoft.com