|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
HttpWebRequestSeems like thre ought to be a better way to get the returned string in a
string variable than this. Anyone know of one? Dim REQUEST As Net.HttpWebRequest Dim RESPONSE As Net.HttpWebResponse Dim oString As IO.Stream Dim RESP_STRING As String Dim URI As String = "http://192.168.168.102/validate/webform1.aspx?" & _ element(2) & "&" & element(3) & "&" & element(4) & _ "&" & element(5) & "&" & element(6) REQUEST = Net.HttpWebRequest.Create(URI) RESPONSE = REQUEST.GetResponse oString = RESPONSE.GetResponseStream RESP_STRING = New IO.StreamReader(oString).ReadToEnd RESPONSE.Close() Maybe I'm not understanding whats going on here but is the answer as
simple as using Request.QueryString() Dim strElement1 as String = Request.QueryString("element1") Dim strElement2 as String = Request.QueryString("element2") Hope you find the answer, Jeremy Reid http://blackstaronline.net/hgtit Hi Cj,
I think the current code you used is the correct means to read response HTML/TEXT content from HttpWebResponse. So far there is no other simplier approach. Or is the better one you mentioned mean anything else? Regards, Steven Cheng Microsoft Online Support Get Secure! www.microsoft.com/security (This posting is provided "AS IS", with no warranties, and confers no rights.) I was looking for something simpler. This first retrieves the response
as a response type then converts it to a stream then finally gives me what I want a simple string. I still find it hard to accept all the stuff I have to go through to get for instance a simple string for something in .net. Steven Cheng[MSFT] wrote: Show quoteHide quote > Hi Cj, > > I think the current code you used is the correct means to read response > HTML/TEXT content from HttpWebResponse. So far there is no other simplier > approach. Or is the better one you mentioned mean anything else? > > Regards, > > Steven Cheng > Microsoft Online Support > > Get Secure! www.microsoft.com/security > (This posting is provided "AS IS", with no warranties, and confers no > rights.) > Thanks for your response Cj,
Yes, we need to first get the Stream of the response and then read data from it. Actually HttpWebResponse's response stream could contains not only plain text data (like html or xml...), but also binary data(like pdf, exe or ...). So it's reasonable that we retrieve data through a stream which contains the raw binary data rather than only provide simple string. In addition, if you're sure in your case the response content are plain text stream, you can use WebClient class to request the data from remote url. The DownLoadData method will return a byte array (byte[]) and you can use the certain Encoding class to decode it into string. Make sure you use the correct encoding type(ascii or utf-8 or any other language specific charset encoding) according to your scenario... #WebClient.DownloadData Method http://msdn.microsoft.com/library/en-us/cpref/html/frlrfsystemnetwebclientcl assdownloaddatatopic.asp?frame=true Hope this helps. Regards, Steven Cheng Microsoft Online Support Get Secure! www.microsoft.com/security (This posting is provided "AS IS", with no warranties, and confers no rights.) The web site you refer me to comes up with a MS site that says "Location
can not be found" Anyway, I think I'll stick with what I've got. Thanks for the reply. Steven Cheng[MSFT] wrote: Show quoteHide quote > Thanks for your response Cj, > > Yes, we need to first get the Stream of the response and then read data > from it. Actually HttpWebResponse's response stream could contains not only > plain text data (like html or xml...), but also binary data(like pdf, exe > or ...). So it's reasonable that we retrieve data through a stream which > contains the raw binary data rather than only provide simple string. > > In addition, if you're sure in your case the response content are plain > text stream, you can use WebClient class to request the data from remote > url. The DownLoadData method will return a byte array (byte[]) and you can > use the certain Encoding class to decode it into string. Make sure you use > the correct encoding type(ascii or utf-8 or any other language specific > charset encoding) according to your scenario... > > #WebClient.DownloadData Method > http://msdn.microsoft.com/library/en-us/cpref/html/frlrfsystemnetwebclientcl > assdownloaddatatopic.asp?frame=true > > Hope this helps. > > Regards, > > Steven Cheng > Microsoft Online Support > > Get Secure! www.microsoft.com/security > (This posting is provided "AS IS", with no warranties, and confers no > rights.) > > Thanks for your response Cj,
The link could have been broken by the line feed in the web page. Anyway, if you can also lookup the "WebClient" class in your local MSDN library. Regards, Steven Cheng Microsoft Online Support Get Secure! www.microsoft.com/security (This posting is provided "AS IS", with no warranties, and confers no rights.) Your right, normall I catch that but this time I just clicked and didn't
notice the link continued on the next line. Sorry. I think I'll stick with what I've got for now but I'll make a note to check "WebClient" sometime. Thanks again Steven Cheng[MSFT] wrote: Show quoteHide quote > Thanks for your response Cj, > > The link could have been broken by the line feed in the web page. Anyway, > if you can also lookup the "WebClient" class in your local MSDN library. > > Regards, > > Steven Cheng > Microsoft Online Support > > Get Secure! www.microsoft.com/security > (This posting is provided "AS IS", with no warranties, and confers no > rights.) > That's fine. Thanks for your followup.
Good luck! Regards, Steven Cheng Microsoft Online Support Get Secure! www.microsoft.com/security (This posting is provided "AS IS", with no warranties, and confers no rights.)
Using Rich Text Box - make a line bold
Beginners problem with multiple forms Combobox and Values - Help Please DateTime structure is there a way to do this How to split a form when coding? Regex help needed Bind Enum to ComboBox in GridView Scaling Graphics (Fractal) TopMost Form within a .net application |
|||||||||||||||||||||||