Created
December 12, 2012 19:19
-
-
Save mgrigajtis/4270718 to your computer and use it in GitHub Desktop.
jSearch Addon
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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