简体   繁体   中英

AxWebBrowser : Download file when already logged in

I am trying to "download" a file using the AxWebbrowser in VB.Net language (though, the answer could be in C#, I don't matter). The browser is already logged in, so I tried to catch the download, but for now the test is done with a PDF and I think it is opened directly in the browser. OK, lets put you in the context.

  • AxWebbrowser going to a login page which I use JavaScript to fill it and continue
  • Navigating to a message page which includes links to attached files
  • Trying to download these files (in fact, trying to get their bytes to transform them in Base64 and include them in my HTML returned... so now the only problem is getting the bytes, after that, conversion + inclusion is something I know)

So, I tried to pass to the browser the URL directly and detect the download and catch the bytes ==> Not able to.

I tried to use a WebClient which I set the cookies, but it doesn't work. Though, using this and comparing with Chrome, I see the cookies aren't the same (in fact I can highly presume there is one important missing).

So, either why I don't get all the cookies or how could I get the bytes from these files?

I got it!!! Finally thought to search how to "save as" a file and then got it.

https://www.codeproject.com/tips/659004/download-of-file-with-open-save-dialog-box

Using GetGlobalCookies got me the proper cookies and the file is downloaded correctly using Webclient . Oh yeah!

-- I removed my duplicate answer to another question. I answered another question by mistake --

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM