HttpWebRequest

C

cj

Seems 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()
 
J

jreid

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
 
S

Steven Cheng[MSFT]

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.)
 
C

cj

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.
 
S

Steven Cheng[MSFT]

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.)
 
C

cj

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.
 
S

Steven Cheng[MSFT]

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.)
 
C

cj

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
 
S

Steven Cheng[MSFT]

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.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top