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

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
 
C

Cor Ligthert [MVP]

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top