Who to change GET to POST Method in this code?

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

    #1

    Who to change GET to POST Method in this code?

    Hi everyone,

    I am having a real trouble to figure out how to amend this code to
    switch from GET to POST method.

    --------------------------------------------------------
    Public Function GetPageHTML(ByV al URL As String, Optional ByVal
    TimeoutSeconds As Integer = 10) As String
    ' Retrieves the HTML from the specified URL, using a default
    timeout of 10 seconds
    Dim objRequest As Net.WebRequest
    Dim objResponse As Net.WebResponse
    Dim objStreamReceiv e As System.IO.Strea m
    Dim objEncoding As System.Text.Enc oding
    Dim objStreamRead As System.IO.Strea mReader


    Try
    ' Setup our Web request
    objRequest = Net.WebRequest. Create(URL)
    objRequest.Time out = TimeoutSeconds * 1000


    ' Retrieve data from request
    objResponse = objRequest.GetR esponse
    objStreamReceiv e = objResponse.Get ResponseStream
    objEncoding = System.Text.Enc oding.GetEncodi ng("utf-8")
    objStreamRead = New
    System.IO.Strea mReader(objStre amReceive, objEncoding)
    ' Set function return value
    GetPageHTML = objStreamRead.R eadToEnd()
    ' Check if available, then close response
    If Not objResponse Is Nothing Then
    objResponse.Clo se()
    End If
    Catch
    ' Error occured grabbing data, simply return nothing
    Return ""
    End Try
    End Function
    --------------------------------------------------------



    This code gets the html source from any url you submit to it.
    Can someone tell me what to do?

    I tried to add this line:
    objRequest.Meth od = "POST"
    , right below the TRY, but nothing changed and I really don't know what
    to do next, while all my customers are getting inpatient.

    I am even willing to pay for the answer. THIS IS MY LAST RESOURCE.

    Please let me know.

    Martin

  • m.posseth

    #2
    Re: Who to change GET to POST Method in this code?

    and

    what is the info you want to post to the webpage ???




    "MARTIN LANNY" <martin.lanny@g mail.com> wrote in message
    news:1126441561 .165405.18240@g 44g2000cwa.goog legroups.com...[color=blue]
    > Hi everyone,
    >
    > I am having a real trouble to figure out how to amend this code to
    > switch from GET to POST method.
    >
    > --------------------------------------------------------
    > Public Function GetPageHTML(ByV al URL As String, Optional ByVal
    > TimeoutSeconds As Integer = 10) As String
    > ' Retrieves the HTML from the specified URL, using a default
    > timeout of 10 seconds
    > Dim objRequest As Net.WebRequest
    > Dim objResponse As Net.WebResponse
    > Dim objStreamReceiv e As System.IO.Strea m
    > Dim objEncoding As System.Text.Enc oding
    > Dim objStreamRead As System.IO.Strea mReader
    >
    >
    > Try
    > ' Setup our Web request
    > objRequest = Net.WebRequest. Create(URL)
    > objRequest.Time out = TimeoutSeconds * 1000
    >
    >
    > ' Retrieve data from request
    > objResponse = objRequest.GetR esponse
    > objStreamReceiv e = objResponse.Get ResponseStream
    > objEncoding = System.Text.Enc oding.GetEncodi ng("utf-8")
    > objStreamRead = New
    > System.IO.Strea mReader(objStre amReceive, objEncoding)
    > ' Set function return value
    > GetPageHTML = objStreamRead.R eadToEnd()
    > ' Check if available, then close response
    > If Not objResponse Is Nothing Then
    > objResponse.Clo se()
    > End If
    > Catch
    > ' Error occured grabbing data, simply return nothing
    > Return ""
    > End Try
    > End Function
    > --------------------------------------------------------
    >
    >
    >
    > This code gets the html source from any url you submit to it.
    > Can someone tell me what to do?
    >
    > I tried to add this line:
    > objRequest.Meth od = "POST"
    > , right below the TRY, but nothing changed and I really don't know what
    > to do next, while all my customers are getting inpatient.
    >
    > I am even willing to pay for the answer. THIS IS MY LAST RESOURCE.
    >
    > Please let me know.
    >
    > Martin
    >[/color]


    Comment

    • m.posseth

      #3
      Re: Who to change GET to POST Method in this code?

      and

      what is the info you want to post to the webpage ???




      "MARTIN LANNY" <martin.lanny@g mail.com> wrote in message
      news:1126441561 .165405.18240@g 44g2000cwa.goog legroups.com...[color=blue]
      > Hi everyone,
      >
      > I am having a real trouble to figure out how to amend this code to
      > switch from GET to POST method.
      >
      > --------------------------------------------------------
      > Public Function GetPageHTML(ByV al URL As String, Optional ByVal
      > TimeoutSeconds As Integer = 10) As String
      > ' Retrieves the HTML from the specified URL, using a default
      > timeout of 10 seconds
      > Dim objRequest As Net.WebRequest
      > Dim objResponse As Net.WebResponse
      > Dim objStreamReceiv e As System.IO.Strea m
      > Dim objEncoding As System.Text.Enc oding
      > Dim objStreamRead As System.IO.Strea mReader
      >
      >
      > Try
      > ' Setup our Web request
      > objRequest = Net.WebRequest. Create(URL)
      > objRequest.Time out = TimeoutSeconds * 1000
      >
      >
      > ' Retrieve data from request
      > objResponse = objRequest.GetR esponse
      > objStreamReceiv e = objResponse.Get ResponseStream
      > objEncoding = System.Text.Enc oding.GetEncodi ng("utf-8")
      > objStreamRead = New
      > System.IO.Strea mReader(objStre amReceive, objEncoding)
      > ' Set function return value
      > GetPageHTML = objStreamRead.R eadToEnd()
      > ' Check if available, then close response
      > If Not objResponse Is Nothing Then
      > objResponse.Clo se()
      > End If
      > Catch
      > ' Error occured grabbing data, simply return nothing
      > Return ""
      > End Try
      > End Function
      > --------------------------------------------------------
      >
      >
      >
      > This code gets the html source from any url you submit to it.
      > Can someone tell me what to do?
      >
      > I tried to add this line:
      > objRequest.Meth od = "POST"
      > , right below the TRY, but nothing changed and I really don't know what
      > to do next, while all my customers are getting inpatient.
      >
      > I am even willing to pay for the answer. THIS IS MY LAST RESOURCE.
      >
      > Please let me know.
      >
      > Martin
      >[/color]


      Comment

      • MARTIN LANNY

        #4
        Re: Who to change GET to POST Method in this code?

        Url includes the name and password:

        Using above code I would submit this url:

        https://www.google.com/adsense/login.do?username=[E-MAIL]&password=[PASSWORD]

        , but google won't let me in, because they switched from GET to POST
        method.

        Now my whole application is stuck as I have no luck amending my code to
        use it as POST method.

        Please let me know how to get around this.

        Martin

        Comment

        • MARTIN LANNY

          #5
          Re: Who to change GET to POST Method in this code?

          Url includes the name and password:

          Using above code I would submit this url:

          https://www.google.com/adsense/login.do?username=[E-MAIL]&password=[PASSWORD]

          , but google won't let me in, because they switched from GET to POST
          method.

          Now my whole application is stuck as I have no luck amending my code to
          use it as POST method.

          Please let me know how to get around this.

          Martin

          Comment

          • m.posseth

            #6
            Re: Who to change GET to POST Method in this code?

            well then this should do the trick

            Imports System.Text

            Imports System.Net

            Imports System.Collecti ons.Specialized

            Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
            System.EventArg s) Handles Button1.Click

            Dim myWebClient As New WebClient

            Dim myNameValueColl ection As New NameValueCollec tion

            myNameValueColl ection.Add("use rname", "john doe")

            myNameValueColl ection.Add("pas sword", "12345")

            Dim responseArray As Byte() =
            myWebClient.Upl oadValues("http s://www.google.com/adsense/login.do", "POST",
            myNameValueColl ection)

            MsgBox(Encoding .UTF8.GetString (responseArray) )

            End Sub





            i do not have a username and password to test it but i believe it should
            work



            regards



            Michel Posseth [MCP]








            "MARTIN LANNY" <martin.lanny@g mail.com> wrote in message
            news:1126457782 .498497.257630@ z14g2000cwz.goo glegroups.com.. .[color=blue]
            > Url includes the name and password:
            >
            > Using above code I would submit this url:
            >
            > https://www.google.com/adsense/login.do?username=[E-MAIL]&password=[PASSWORD]
            >
            > , but google won't let me in, because they switched from GET to POST
            > method.
            >
            > Now my whole application is stuck as I have no luck amending my code to
            > use it as POST method.
            >
            > Please let me know how to get around this.
            >
            > Martin
            >[/color]


            Comment

            • m.posseth

              #7
              Re: Who to change GET to POST Method in this code?

              well then this should do the trick

              Imports System.Text

              Imports System.Net

              Imports System.Collecti ons.Specialized

              Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
              System.EventArg s) Handles Button1.Click

              Dim myWebClient As New WebClient

              Dim myNameValueColl ection As New NameValueCollec tion

              myNameValueColl ection.Add("use rname", "john doe")

              myNameValueColl ection.Add("pas sword", "12345")

              Dim responseArray As Byte() =
              myWebClient.Upl oadValues("http s://www.google.com/adsense/login.do", "POST",
              myNameValueColl ection)

              MsgBox(Encoding .UTF8.GetString (responseArray) )

              End Sub





              i do not have a username and password to test it but i believe it should
              work



              regards



              Michel Posseth [MCP]








              "MARTIN LANNY" <martin.lanny@g mail.com> wrote in message
              news:1126457782 .498497.257630@ z14g2000cwz.goo glegroups.com.. .[color=blue]
              > Url includes the name and password:
              >
              > Using above code I would submit this url:
              >
              > https://www.google.com/adsense/login.do?username=[E-MAIL]&password=[PASSWORD]
              >
              > , but google won't let me in, because they switched from GET to POST
              > method.
              >
              > Now my whole application is stuck as I have no luck amending my code to
              > use it as POST method.
              >
              > Please let me know how to get around this.
              >
              > Martin
              >[/color]


              Comment

              • MARTIN LANNY

                #8
                Re: Who to change GET to POST Method in this code?

                Thanks to you, I have this code (below) to login to specified URL with
                my username and
                psw and get the resulting HTML code.
                It's using "POST" method.


                It works just fine when result (after login) is a page.


                But in some cases, result isn't a page, but a download file.


                In case the resulting page is a download file (csv file I am
                downloading from google adsense) it will not read the response.
                It gives me no result whatsoever.


                Can someone tell me how to amend this code, so it also reads the
                content of the file?


                Public Function GetPageHTML(ByV al URL As String, Optional ByVal
                TimeoutSeconds As Integer = 10) As String
                Try
                Dim myWebClient As New WebClient
                Dim myNameValueColl ection As New NameValueCollec tion
                myNameValueColl ection.Add("use rname", "joedoe")
                myNameValueColl ection.Add("pas sword", "123456")
                Dim responseArray As Byte() = myWebClient.Upl oadValues(URL,

                "POST", myNameValueColl ection)
                GetPageHTML = Encoding.UTF8.G etString(respon seArray)
                Catch ex As Exception
                ' Error occured grabbing data, simply return nothing
                Return ""
                End Try
                End Function


                Thanks for every answer.
                Martin

                Comment

                • MARTIN LANNY

                  #9
                  Re: Who to change GET to POST Method in this code?

                  Thanks to you, I have this code (below) to login to specified URL with
                  my username and
                  psw and get the resulting HTML code.
                  It's using "POST" method.


                  It works just fine when result (after login) is a page.


                  But in some cases, result isn't a page, but a download file.


                  In case the resulting page is a download file (csv file I am
                  downloading from google adsense) it will not read the response.
                  It gives me no result whatsoever.


                  Can someone tell me how to amend this code, so it also reads the
                  content of the file?


                  Public Function GetPageHTML(ByV al URL As String, Optional ByVal
                  TimeoutSeconds As Integer = 10) As String
                  Try
                  Dim myWebClient As New WebClient
                  Dim myNameValueColl ection As New NameValueCollec tion
                  myNameValueColl ection.Add("use rname", "joedoe")
                  myNameValueColl ection.Add("pas sword", "123456")
                  Dim responseArray As Byte() = myWebClient.Upl oadValues(URL,

                  "POST", myNameValueColl ection)
                  GetPageHTML = Encoding.UTF8.G etString(respon seArray)
                  Catch ex As Exception
                  ' Error occured grabbing data, simply return nothing
                  Return ""
                  End Try
                  End Function


                  Thanks for every answer.
                  Martin

                  Comment

                  Working...