PC Review


Reply
Thread Tools Rate Thread

Who to change GET to POST Method in this code?

 
 
MARTIN LANNY
Guest
Posts: n/a
 
      11th Sep 2005
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(ByVal 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 objStreamReceive As System.IO.Stream
Dim objEncoding As System.Text.Encoding
Dim objStreamRead As System.IO.StreamReader


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


' Retrieve data from request
objResponse = objRequest.GetResponse
objStreamReceive = objResponse.GetResponseStream
objEncoding = System.Text.Encoding.GetEncoding("utf-8")
objStreamRead = New
System.IO.StreamReader(objStreamReceive, objEncoding)
' Set function return value
GetPageHTML = objStreamRead.ReadToEnd()
' Check if available, then close response
If Not objResponse Is Nothing Then
objResponse.Close()
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.Method = "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

 
Reply With Quote
 
 
 
 
m.posseth
Guest
Posts: n/a
 
      11th Sep 2005
and

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




"MARTIN LANNY" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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(ByVal 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 objStreamReceive As System.IO.Stream
> Dim objEncoding As System.Text.Encoding
> Dim objStreamRead As System.IO.StreamReader
>
>
> Try
> ' Setup our Web request
> objRequest = Net.WebRequest.Create(URL)
> objRequest.Timeout = TimeoutSeconds * 1000
>
>
> ' Retrieve data from request
> objResponse = objRequest.GetResponse
> objStreamReceive = objResponse.GetResponseStream
> objEncoding = System.Text.Encoding.GetEncoding("utf-8")
> objStreamRead = New
> System.IO.StreamReader(objStreamReceive, objEncoding)
> ' Set function return value
> GetPageHTML = objStreamRead.ReadToEnd()
> ' Check if available, then close response
> If Not objResponse Is Nothing Then
> objResponse.Close()
> 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.Method = "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
>



 
Reply With Quote
 
 
 
 
MARTIN LANNY
Guest
Posts: n/a
 
      11th Sep 2005
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

 
Reply With Quote
 
m.posseth
Guest
Posts: n/a
 
      11th Sep 2005
well then this should do the trick

Imports System.Text

Imports System.Net

Imports System.Collections.Specialized

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim myWebClient As New WebClient

Dim myNameValueCollection As New NameValueCollection

myNameValueCollection.Add("username", "john doe")

myNameValueCollection.Add("password", "12345")

Dim responseArray As Byte() =
myWebClient.UploadValues("https://www.google.com/adsense/login.do", "POST",
myNameValueCollection)

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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>



 
Reply With Quote
 
MARTIN LANNY
Guest
Posts: n/a
 
      12th Sep 2005
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(ByVal URL As String, Optional ByVal
TimeoutSeconds As Integer = 10) As String
Try
Dim myWebClient As New WebClient
Dim myNameValueCollection As New NameValueCollection
myNameValueCollection.Add("username", "joedoe")
myNameValueCollection.Add("password", "123456")
Dim responseArray As Byte() = myWebClient.UploadValues(URL,

"POST", myNameValueCollection)
GetPageHTML = Encoding.UTF8.GetString(responseArray)
Catch ex As Exception
' Error occured grabbing data, simply return nothing
Return ""
End Try
End Function


Thanks for every answer.
Martin

 
Reply With Quote
 
 
 
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
sub to get post code to post code mileage from web site Atishoo Microsoft Excel Programming 3 29th Jun 2009 03:20 PM
Please post this thread a correct full method, method about Nast Runsome Microsoft Excel New Users 8 25th Feb 2008 04:29 PM
Please post this thread a complete correct method, method about te Nast Runsome Microsoft Excel New Users 0 23rd Feb 2008 10:42 PM
how can I change this get code to post code cj Microsoft VB .NET 10 5th Sep 2007 04:43 AM
Post data via the Post method in asp.net? (URGENT) Vishal Microsoft ASP .NET 1 21st Dec 2004 07:14 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:54 AM.