Search:
Namespaces
Discussions
.NET v1.1
Feedback
HttpWebRequest - GET Method
Messages
Related Types
This message was discovered on
ASPFriends.com 'ngfx-io' list
.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.
Jim Davis
I'd like to GET the page inside an HTTPWEBREQUEST Class, but it doesn't seem
to like GET as the Method.
Keeps displaying the following error.
Cannot send a content-body with this verb-type.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.
Exception Details: System.Net.ProtocolViolationException: Cannot send a
content-body with this verb-type.
Source Error:
Line 25: ' Add body to request
Line 26: objRequest.ContentLength = arrRequest.Length
Line 27: strmRequest = objRequest.GetRequestStream()
Line 28: strmRequest.Write( arrRequest, 0, arrRequest.Length )
Line 29: strmRequest.Close()
Sub Button_Click( s As Object, e As
EventArgs
)
Dim objRequest As
HttpWebRequest
Dim strRequest As String
Dim arrRequest As Byte()
Dim objUTF8Encoding As
UTF8Encoding
Dim strmRequest As Stream
Dim objResponse As
HttpWebResponse
Dim srResponse As
StreamReader
' Initialize request object
objRequest = CType(
WebRequest
.Create( txtMessage.Text.ToString() ),
HttpWebRequest
)
objRequest.Method = "GET"
objRequest.ContentType = "application/x-www-form-urlencoded"
' Create request body
strRequest = "Message=" & Server.UrlEncode( txtMessage.Text )
objUTF8Encoding = New
UTF8Encoding
arrRequest = objUTF8Encoding.GetBytes( strRequest )
' Add body to request
objRequest.ContentLength = arrRequest.Length
strmRequest = objRequest.GetRequestStream()
strmRequest.Write( arrRequest, 0, arrRequest.Length )
strmRequest.Close()
' Get response
objResponse = objRequest.GetResponse()
srResponse = New
StreamReader
( objResponse.GetResponseStream(),
Encoding
.ASCII )
lblResponse.Text = srResponse.ReadToEnd()
srResponse.Close()
End Sub
Ideas?
Thanks,
Jim Davis
.NET Web Developer
Reply to this message...
Devin Rader
I'm not sure you can do this with the
HttpWebRequest
classes. I think you
might have to go a little lower and either use the
TcpClient
or a Socket.
Devin
-----Original Message-----
From: Jim Davis [mailto:
Click here to reveal e-mail address
]
Sent: Monday, May 06, 2002 3:54 PM
To: ngfx-io
Subject: [ngfx-io]
HttpWebRequest
- GET Method
I'd like to GET the page inside an HTTPWEBREQUEST Class, but it doesn't seem
to like GET as the Method.
Keeps displaying the following error.
Cannot send a content-body with this verb-type.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.
Exception Details: System.Net.ProtocolViolationException: Cannot send a
content-body with this verb-type.
Source Error:
Line 25: ' Add body to request
Line 26: objRequest.ContentLength = arrRequest.Length
Line 27: strmRequest = objRequest.GetRequestStream()
Line 28: strmRequest.Write( arrRequest, 0, arrRequest.Length )
Line 29: strmRequest.Close()
Sub Button_Click( s As Object, e As
EventArgs
)
Dim objRequest As HttpWebRequest
Dim strRequest As String
Dim arrRequest As Byte()
Dim objUTF8Encoding As UTF8Encoding
Dim strmRequest As Stream
Dim objResponse As HttpWebResponse
Dim srResponse As StreamReader
' Initialize request object
objRequest = CType(
WebRequest
.Create( txtMessage.Text.ToString() ),
HttpWebRequest
)
objRequest.Method = "GET"
objRequest.ContentType = "application/x-www-form-urlencoded"
' Create request body
strRequest = "Message=" & Server.UrlEncode( txtMessage.Text )
objUTF8Encoding = New UTF8Encoding
arrRequest = objUTF8Encoding.GetBytes( strRequest )
' Add body to request
objRequest.ContentLength = arrRequest.Length
strmRequest = objRequest.GetRequestStream()
strmRequest.Write( arrRequest, 0, arrRequest.Length )
strmRequest.Close()
' Get response
objResponse = objRequest.GetResponse()
srResponse = New
StreamReader
( objResponse.GetResponseStream(),
Encoding
.ASCII )
lblResponse.Text = srResponse.ReadToEnd()
srResponse.Close()
End Sub
Ideas?
Thanks,
Jim Davis
.NET Web Developer
| [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...
Mitch Denny (VIP)
Jim,
Try using a POST. When using the GET method the input
data must be URL encoded, not encoded in the payload
like you do with a POST. Here is an example of a valid
GET request via HTTP:
C: GET /test.aspx?z=a&y=b&x=c HTTP/1.0
C:
C:
Notice how the values are encoded in the GET request.
----------------------------------------
- Mitch Denny
-
Click here to reveal e-mail address
- +61 (414) 610-141
-
-----Original Message-----
From: Jim Davis [mailto:
Click here to reveal e-mail address
]
Sent: Tuesday, 7 May 2002 06:54
To: ngfx-io
Subject: [ngfx-io]
HttpWebRequest
- GET Method
I'd like to GET the page inside an HTTPWEBREQUEST Class, but it doesn't
seem to like GET as the Method.
Keeps displaying the following error.
Cannot send a content-body with this verb-type.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.
Exception Details: System.Net.ProtocolViolationException: Cannot send a
content-body with this verb-type.
Source Error:
Line 25: ' Add body to request
Line 26: objRequest.ContentLength = arrRequest.Length
Line 27: strmRequest = objRequest.GetRequestStream()
Line 28: strmRequest.Write( arrRequest, 0, arrRequest.Length )
Line 29: strmRequest.Close()
Sub Button_Click( s As Object, e As
EventArgs
)
Dim objRequest As
HttpWebRequest
Dim strRequest As String
Dim arrRequest As Byte()
Dim objUTF8Encoding As
UTF8Encoding
Dim strmRequest As Stream
Dim objResponse As
HttpWebResponse
Dim srResponse As
StreamReader
' Initialize request object
objRequest = CType(
WebRequest
.Create( txtMessage.Text.ToString() ),
HttpWebRequest
)
objRequest.Method = "GET"
objRequest.ContentType = "application/x-www-form-urlencoded"
' Create request body
strRequest = "Message=" & Server.UrlEncode( txtMessage.Text )
objUTF8Encoding = New
UTF8Encoding
arrRequest = objUTF8Encoding.GetBytes( strRequest )
' Add body to request
objRequest.ContentLength = arrRequest.Length
strmRequest = objRequest.GetRequestStream()
strmRequest.Write( arrRequest, 0, arrRequest.Length )
strmRequest.Close()
' Get response
objResponse = objRequest.GetResponse()
srResponse = New
StreamReader
( objResponse.GetResponseStream(),
Encoding
.ASCII )
lblResponse.Text = srResponse.ReadToEnd()
srResponse.Close()
End Sub
Ideas?
Thanks,
Jim Davis
.NET Web Developer
| [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...
System.EventArgs
System.IO.StreamReader
System.Net.HttpWebRequest
System.Net.HttpWebResponse
System.Net.ProtocolViolationException
System.Net.Sockets.TcpClient
System.Net.WebRequest
System.Text.Encoding
System.Text.UTF8Encoding
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