WebBrowser Control download file in session

后端 未结 2 861
情歌与酒
情歌与酒 2021-02-09 11:07

I\'m using WebBrowser control to navigate through a login page and download a file. Since I can\'t find a way to manage the download automatically with the control

2条回答
  •  粉色の甜心
    2021-02-09 11:53

    It should be simply a matter of emulating the cookies and headers in the WebBrowser session and re-using them to impersonate the session in WebClient, but it looks like you're already hot on that path.

    Here's how I'd proceed.

    1. Get cookies and headers from WebBrowser.

      Cookies: You can get the cookies from your WebBrowser session by handling the DocumentCompleted event of the WebBrowser control and parsing the cookie set from DocumentCompleted event.

      Headers: Use a proxy like Fiddler [www.fiddler2.com/] to read the headers so you'll know what's required by the server.

    2. Utilize identity collected above for WebClient.

      Headers: Iterate through all your collected headers and be sure they are added to the webclient using myWebClient.Headers.Add("Content-Type","application/x-www-form-urlencoded"); for example

      Cookies: See this post.

提交回复
热议问题