Skip to content

Instantly share code, notes, and snippets.

@mgrigajtis
Created December 12, 2012 19:19
Show Gist options
  • Save mgrigajtis/4270718 to your computer and use it in GitHub Desktop.
Save mgrigajtis/4270718 to your computer and use it in GitHub Desktop.
jSearch Addon
Imports System.Net
Imports System.Web
Imports System.Web.Services
Public Class jSearch
Implements System.Web.IHttpHandler
Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
Dim byteRequestedHtml() As Byte = Nothing
Dim objUtf8 As UTF8Encoding = Nothing
Dim objWebClient As WebClient = Nothing
Dim strUrlToSearch As String = String.Empty
Try
If context.Request.RequestType = "POST" Then
If Trim(HttpContext.Current.Request.Form("searchUrl")) <> String.Empty Then
strUrlToSearch = Trim(HttpContext.Current.Request.Form("searchUrl"))
objWebClient = New WebClient
byteRequestedHtml = objWebClient.DownloadData(strUrlToSearch)
objUtf8 = New UTF8Encoding
context.Response.ContentType = "text/plain"
context.Response.Write(objUtf8.GetString(byteRequestedHtml))
End If
End If
Catch ex As Exception
' Handle exception
Finally
byteRequestedHtml = Nothing
objUtf8 = Nothing
If objWebClient IsNot Nothing Then
objWebClient.Dispose()
objWebClient = Nothing
End If
strUrlToSearch = Nothing
End Try
End Sub
ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
Get
Return False
End Get
End Property
End Class
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment