473,400 Members | 2,163 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,400 software developers and data experts.

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(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

Nov 21 '05 #1
8 2085
and

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


"MARTIN LANNY" <ma**********@gmail.com> wrote in message
news:11*********************@g44g2000cwa.googlegro ups.com...
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

Nov 21 '05 #2
and

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


"MARTIN LANNY" <ma**********@gmail.com> wrote in message
news:11*********************@g44g2000cwa.googlegro ups.com...
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

Nov 21 '05 #3
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

Nov 21 '05 #4
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

Nov 21 '05 #5
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" <ma**********@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
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

Nov 21 '05 #6
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" <ma**********@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
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

Nov 21 '05 #7
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

Nov 21 '05 #8
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

Nov 21 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Christiaan | last post by:
I am trying to create a small javascript to change the button text and then submit it and do all kinds of form validations. So I have a button with the value "Save", when the button is clicked it...
14
by: Reply Via Newsgroup | last post by:
Folks, Say I have a table, ten columns, ten rows - Each with a word in it. I want to change the values of some/all of the cells in the table via a hyperlink. How do I reference each cell and...
2
by: juglesh | last post by:
hi, all, thanks for reading. i have a form in which i want drop down boxes to dynamically change some hidden fields: http://cynthialoganjewelry.com/test4.htm <form name=test method="post" > ...
34
by: Andrew DeFaria | last post by:
I thought this would be fairly straight forward but apparently it's not. Given the following html file: <!DOCTYPE html PUBLIC "-//w3c//dtd html 4.0 transitional//en"> <html> <head>...
0
by: MARTIN LANNY | last post by:
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...
10
by: IchBin | last post by:
I am trying to set the state of a radio button. I do not see what I am doing wrong. Sorry, I am new at this.. I need another set of eyes to look at this snip of code. I am trying to set the radio...
6
by: Arthur | last post by:
Hello. How might it be possible to change where a form action is directed based on a selected option. For example I have this: <FORM METHOD = "post" ACTION = ""> And a drop down such as
1
by: webandwe | last post by:
Hi, Can somebody please show me how to change the connection so I can make it work with my MYSQL database... I just need this login to work then I'm done wiht my project. I don't know what is...
5
by: thatcollegeguy | last post by:
Below are my 3php and 2js files. I create a table using ajax/php and then want to change the values in the tables add(+ number for teamid) id's for each specific td in the table. I don't know...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.