HttpWebRequest Form POST

vbnetcoder2005

Newcomer
Joined
Sep 28, 2005
Messages
2
I am trying to POST data to a form in my VB.net app and am getting an error from the particular web server that an HTTP protocal has been. When I anaylzed the data the my app is passing versus a web browser for example I noticed that the test my application is sending is plain text such as this.

message= this is a regular message

While the web browser was sending information like this:

message= this+is+a+regular+message

Is there sometype of library in VB.net that will convert my plain text to the format the web server would like to see. Note here is my VB.net code POST code snippet:

' Send Request, If Request
If (Method = HTTPMethod.HTTP_POST) Then
Try
If RefererURL <> "" Then
Request.Referer = RefererURL
End If
SW = New StreamWriter(Request.GetRequestStream())
SW.Write(PostData)
Catch Err As WebException
MsgBox(Err.Message, MsgBoxStyle.Information, "Error")

Finally
Try
SW.Close()
Catch
'Don't process an error from SW not closing
End Try
End Try
End If
 
Do you mean your program sends this "Classic Active Server Pages" and a real webbrowser sends "Classic%20Active%20Server%20Pages"? If that is the case you will probably need to convert nonalpha characters (space, comma, quote, period, etc) to it's ASCII HEX value. I'm not 100% sure about that though.
 
Nate Bross said:
Do you mean your program sends this "Classic Active Server Pages" and a real webbrowser sends "Classic%20Active%20Server%20Pages"? If that is the case you will probably need to convert nonalpha characters (space, comma, quote, period, etc) to it's ASCII HEX value. I'm not 100% sure about that though.

Thanks for the reply Nate, I acutally figured it out. You have to use the System.Web.HttpUtility to encode the text for what some web forms accept as readable text in the "application/x-www-form-urlencoded" format. I used the following code.

src = HttpUtility.UrlEncode(strText)


This will take a string such as this "this is a string"
and encode it like so "this+is+a+string" this seemed to work even though I couldn't find a great deal of documentation on the subject (not even on MSDN). I do think that most web servers however will take plain text in their form variables and it is not necessary to do this type of encoding.

VbNetCoder2005
 
This may be a strange request, but I am trying to to the same thing but my app has an/gets and error when creating the data object to send. Now this doesn't happen all the time but maybe three times a day which is annoying. Could you post more of your coade as an example for me to look at.

Thanks

ZeroEffect
 
Back
Top