sending http post request
Messages   Related Types
This message was discovered on ASPFriends.com 'ngfx-io' list.


Peter Weng
Hi,

How would I go about sending an http post request programmatically?
HttpWebRequest class?

For instance let's say I have a page that take form variables and puts
those form variables into a database. Is there a way to send an http
post request to that form programmatically? Note that I can't just
generate a webrequest with the form variables in the query string since
my page only accepts it from the form object which I assume is in the
http message body?

-Peter
Reply to this message...
 
    
Peter Brunone
Peter,

    The function below takes an absolute URL and parameters in the form of
"param1=blah¶m2=bloh", makes a POST request, and returns the resulting
HTML page as a string.
    Watch for wrapping.

Cheers,

Peter

***************************

Function readHtmlPage(ByVal url As String, ByVal params As String) As
String
Dim result As String = ""
Dim myWriter As StreamWriter

Dim objRequest As HttpWebRequest = WebRequest.Create(url)
objRequest.Method = "POST"
objRequest.ContentLength = params.Length
objRequest.ContentType = "application/x-www-form-urlencoded"
objRequest.KeepAlive = False

Try
myWriter = New StreamWriter(objRequest.GetRequestStream())
myWriter.Write(params)
Catch e As Exception
Return e.Message
Finally
myWriter.Close()
End Try

Dim objResponse As HttpWebResponse = objRequest.GetResponse()
Dim sr As StreamReader
sr = New StreamReader(objResponse.GetResponseStream())
result = sr.ReadToEnd()
sr.Close()

myWriter.Close()

Return result
End Function

|-----Original Message-----
|From: Peter Weng [mailto:Click here to reveal e-mail address]
|
|Hi,
|
|How would I go about sending an http post request programmatically?
|HttpWebRequest class?
|
|For instance let's say I have a page that take form variables and puts
|those form variables into a database. Is there a way to send an http
|post request to that form programmatically? Note that I can't just
|generate a webrequest with the form variables in the query string since
|my page only accepts it from the form object which I assume is in the
|http message body?
|
|-Peter

Reply to this message...
 
    
Devin Rader
Yes..I know how to use the WebRequest/Response objects...I am look for OTHER
ways to do this WITHOUT having to use those objects.

Devin

-----Original Message-----
From: Peter Brunone [mailto:Click here to reveal e-mail address]
Sent: Thursday, April 25, 2002 10:22 AM
To: ngfx-io
Subject: [ngfx-io] RE: sending http post request

Peter,

    The function below takes an absolute URL and parameters in the form
of
"param1=blah¶m2=bloh", makes a POST request, and returns the resulting
HTML page as a string.
    Watch for wrapping.

Cheers,

Peter

***************************

Function readHtmlPage(ByVal url As String, ByVal params As String) As
String
Dim result As String = ""
Dim myWriter As StreamWriter

Dim objRequest As HttpWebRequest = WebRequest.Create(url)
objRequest.Method = "POST"
objRequest.ContentLength = params.Length
objRequest.ContentType = "application/x-www-form-urlencoded"
objRequest.KeepAlive = False

Try
myWriter = New StreamWriter(objRequest.GetRequestStream())
myWriter.Write(params)
Catch e As Exception
Return e.Message
Finally
myWriter.Close()
End Try

Dim objResponse As HttpWebResponse = objRequest.GetResponse()
Dim sr As StreamReader
sr = New StreamReader(objResponse.GetResponseStream())
result = sr.ReadToEnd()
sr.Close()

myWriter.Close()

Return result
End Function

|-----Original Message-----
|From: Peter Weng [mailto:Click here to reveal e-mail address]
|
|Hi,
|
|How would I go about sending an http post request programmatically?
|HttpWebRequest class?
|
|For instance let's say I have a page that take form variables and puts
|those form variables into a database. Is there a way to send an http
|post request to that form programmatically? Note that I can't just
|generate a webrequest with the form variables in the query string since
|my page only accepts it from the form object which I assume is in the
|http message body?
|
|-Peter

| [ngfx-io] member Click here to reveal e-mail address = YOUR ID
| http://www.aspfriends.com/aspfriends/ngfx-io.asp = JOIN/QUIT
Reply to this message...
 
    
Jim Davis
Peter,

With ASPTear you could specify the REFERER for the request.

Can this be done with your example?

Jim Davis
.NET Web Developer

-----Original Message-----
From: Peter Brunone [mailto:Click here to reveal e-mail address]
Sent: Thursday, April 25, 2002 11:22 AM
To: ngfx-io
Subject: [ngfx-io] RE: sending http post request

Peter,

    The function below takes an absolute URL and parameters in the form of
"param1=blah¶m2=bloh", makes a POST request, and returns the resulting
HTML page as a string.
    Watch for wrapping.

Cheers,

Peter

***************************

Function readHtmlPage(ByVal url As String, ByVal params As String) As
String
Dim result As String = ""
Dim myWriter As StreamWriter

Dim objRequest As HttpWebRequest = WebRequest.Create(url)
objRequest.Method = "POST"
objRequest.ContentLength = params.Length
objRequest.ContentType = "application/x-www-form-urlencoded"
objRequest.KeepAlive = False

Try
myWriter = New StreamWriter(objRequest.GetRequestStream())
myWriter.Write(params)
Catch e As Exception
Return e.Message
Finally
myWriter.Close()
End Try

Dim objResponse As HttpWebResponse = objRequest.GetResponse()
Dim sr As StreamReader
sr = New StreamReader(objResponse.GetResponseStream())
result = sr.ReadToEnd()
sr.Close()

myWriter.Close()

Return result
End Function

|-----Original Message-----
|From: Peter Weng [mailto:Click here to reveal e-mail address]
|
|Hi,
|
|How would I go about sending an http post request programmatically?
|HttpWebRequest class?
|
|For instance let's say I have a page that take form variables and puts
|those form variables into a database. Is there a way to send an http
|post request to that form programmatically? Note that I can't just
|generate a webrequest with the form variables in the query string since
|my page only accepts it from the form object which I assume is in the
|http message body?
|
|-Peter

| [ngfx-io] member Click here to reveal e-mail address = YOUR ID
| http://www.aspfriends.com/aspfriends/ngfx-io.asp = JOIN/QUIT

Reply to this message...
 
    
Peter Brunone
Jim,

    Absolutely; just use the Referer property, e.g.

objRequest.Referer = "blahblah.aspx"

    The property takes a string value, so stick whatever you want in there.
BTW -- and this is for everyone -- if you don't have a copy of Lutz Roeder's
free .NET Reflector (class browser), I highly recommend downloading it from
http://www.aisto.com/roeder/dotnet .

Cheers,

Peter Brunone

|-----Original Message-----
|From: Jim Davis [mailto:Click here to reveal e-mail address]
|
|Peter,
|
|With ASPTear you could specify the REFERER for the request.
|
|Can this be done with your example?
|
|Jim Davis
|.NET Web Developer
|
|-----Original Message-----
|From: Peter Brunone [mailto:Click here to reveal e-mail address]
|
|Peter,
|
|    The function below takes an absolute URL and parameters in
|the form of
|"param1=blah¶m2=bloh", makes a POST request, and returns the resulting
|HTML page as a string.
|    Watch for wrapping.
|
|Cheers,
|
|Peter
|
|***************************
|
| Function readHtmlPage(ByVal url As String, ByVal params As String) As
|String
| Dim result As String = ""
| Dim myWriter As StreamWriter
|
| Dim objRequest As HttpWebRequest = WebRequest.Create(url)
| objRequest.Method = "POST"
| objRequest.ContentLength = params.Length
| objRequest.ContentType = "application/x-www-form-urlencoded"
| objRequest.KeepAlive = False
|
| Try
| myWriter = New StreamWriter(objRequest.GetRequestStream())
| myWriter.Write(params)
| Catch e As Exception
| Return e.Message
| Finally
| myWriter.Close()
| End Try
|
| Dim objResponse As HttpWebResponse = objRequest.GetResponse()
| Dim sr As StreamReader
| sr = New StreamReader(objResponse.GetResponseStream())
| result = sr.ReadToEnd()
| sr.Close()
|
| myWriter.Close()
|
| Return result
| End Function
|
|
||-----Original Message-----
||From: Peter Weng [mailto:Click here to reveal e-mail address]
||
||Hi,
||
||How would I go about sending an http post request programmatically?
||HttpWebRequest class?
||
||For instance let's say I have a page that take form variables and puts
||those form variables into a database. Is there a way to send an http
||post request to that form programmatically? Note that I can't just
||generate a webrequest with the form variables in the query string since
||my page only accepts it from the form object which I assume is in the
||http message body?
||
||-Peter
|

Reply to this message...
 
 
System.IO.StreamReader
System.IO.StreamWriter
System.Net.HttpWebRequest
System.Net.HttpWebResponse
System.Net.WebRequest




Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
 
 Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us - Terms of Use - Privacy Policy - www.dotnet247.com