HttpWebRequest

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • cj

    #1

    HttpWebRequest

    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.HttpWebRequ est
    Dim RESPONSE As Net.HttpWebResp onse
    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.HttpWebRequ est.Create(URI)
    RESPONSE = REQUEST.GetResp onse
    oString = RESPONSE.GetRes ponseStream
    RESP_STRING = New IO.StreamReader (oString).ReadT oEnd
    RESPONSE.Close( )
  • jreid@blackstaronline.net

    #2
    Re: HttpWebRequest

    Maybe I'm not understanding whats going on here but is the answer as
    simple as using Request.QuerySt ring()

    Dim strElement1 as String = Request.QuerySt ring("element1" )
    Dim strElement2 as String = Request.QuerySt ring("element2" )

    Hope you find the answer,
    Jeremy Reid


    Comment

    • Steven Cheng[MSFT]

      #3
      Re: HttpWebRequest

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

      Comment

      • cj

        #4
        Re: HttpWebRequest

        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:[color=blue]
        > 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.)
        >[/color]

        Comment

        • Steven Cheng[MSFT]

          #5
          Re: HttpWebRequest

          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.Down loadData Method
          http://msdn.microsoft.com/library/en...netwebclientcl
          assdownloaddata topic.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.)


          Comment

          • cj

            #6
            Re: HttpWebRequest

            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:[color=blue]
            > 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.Down loadData Method
            > http://msdn.microsoft.com/library/en...netwebclientcl
            > assdownloaddata topic.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.)
            >
            >[/color]

            Comment

            • Steven Cheng[MSFT]

              #7
              Re: HttpWebRequest

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

              Comment

              • cj

                #8
                Re: HttpWebRequest

                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:[color=blue]
                > 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.)
                >[/color]

                Comment

                • Steven Cheng[MSFT]

                  #9
                  Re: HttpWebRequest

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

                  Comment

                  Working...