vbnetcoder2005 Posted September 28, 2005 Posted September 28, 2005 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 Quote
Nate Bross Posted September 28, 2005 Posted September 28, 2005 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. Quote ~Nate� ___________________________________________ Please use the [vb]/[cs] tags on posted code. Please post solutions you find somewhere else. Follow me on Twitter here.
vbnetcoder2005 Posted September 29, 2005 Author Posted September 29, 2005 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' date=' comma, quote, period, etc) to it's ASCII HEX value. I'm not 100% sure about that though.[/quote'] 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 Quote
ZeroEffect Posted December 16, 2005 Posted December 16, 2005 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 Quote If you can't find it, Build It. There is no place Like 127.0.0.1 also don't forget 1 + 1 = 10
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.