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