WebClient reads html code of the page, but ignores the code of download files.

  • Thread starter Thread starter MARTIN LANNY
  • Start date Start date
M

MARTIN LANNY

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
 
Martin,

I advice you to ask this in the newsgroup

microsoft.public.dotnet.framework.security
and or
microsoft.public.dotnet.security

I have not the idea that you use the most optimal method and in those
newsgroups are more experts for that.

I hope this helps,

Cor
 
Back
Top