Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx thread: Http Request from Windows Service


Message #1 by Terrence Joubert <Terrence@v...> on Mon, 18 Nov 2002 11:32:40 +0400
Hi,
 
I want to send an HTTP Request to a web page from within a windows service.
 
Will appreciate any help on how this can be done.
 
Thanks

 

Terrence J. Joubert

Software Engineer

VCS, PO BOX 1000

Victoria, Mahe

 

 

Message #2 by "Jonathan Larouche" <jlarouche@d...> on Fri, 29 Nov 2002 20:17:08
Put that code where you want to make Http requests
'###############END 
        Dim oRequest As Net.HttpWebRequest
        Dim oResponse As Net.HttpWebResponse
        Dim strUrl as string = "http://www.wrox.com/"

        'SET NEW REQUEST OBJECT
        oRequest = Net.HttpWebRequest.Create(strUrl)
        'DISABLE USE OF AUTO-REDIRECT, IF A REDIRECT IS RESPONNED, YOU 
WILL GET HTML DATA
        oRequest.AllowAutoRedirect = False
        'SET THE METHOD, GET|POST
        oRequest.Method = "GET"

        'IF YOU WANT TO USE POST, USE THIS BLOCK OF CODE
         If oRequest.Method = "POST" Then
         oRequest.ContentType = "application/x-www-form-urlencoded"
         Dim myWriter As New System.IO.StreamWriter
(oRequest.GetRequestStream())
         myWriter.Write("DATATOPOST")
         myWriter.Close()
        End If

        'EXECUTE THE REQUEST AND PUT IT ON RESPONSE OBJECT
        oResponse = oRequest.GetResponse()

        'READ THE RESPONSE INTO A STREAM AND CONVERT IT INTO STRING
        Dim oStm As New System.IO.StreamReader(oResponse.GetResponseStream)

        Dim strResponse as string = oStm.ReadToEnd()
'###############END 
Jonathan

> Hi,
 
I want to send an HTTP Request to a web page from within a windows service.
 
Will appreciate any help on how this can be done.
 
Thanks

 

Terrence J. Joubert

Software Engineer

VCS, PO BOX 1000

Victoria, Mahe

 

 


  Return to Index