How to use HttpWebRequest to download file

前端 未结 3 1248
情歌与酒
情歌与酒 2021-01-05 17:19

Trying to download file in code.

Current code:

  Dim uri As New UriBuilder
    uri.UserName = \"xxx\"
    uri.Password = \"xxx\"
    uri.Host = \"x         


        
相关标签:
3条回答
  • you should check and see if the site requires cookies (most do), i'd use a packet analyzer and run your code and see exactly what the server is returning. use fiddler or http analyzer to log packets

    0 讨论(0)
  • 2021-01-05 17:56

    With UWP, this has become a more pertinent question as UWP does not have a WebClient. The correct answer to this question is if you are being re-directed to the login page, then there must be an issue with your credentials OR the setting (or lack of) header for the HttpWebRequest.

    According to Microsoft, the request for downloading is sent with the call to GetResponse() on the HttpWebRequest, therefore the downloaded file SHOULD be in the stream in the response (returned by the GetResponse() call mentioned above).

    0 讨论(0)
  • 2021-01-05 18:05

    You don't need all of that code to download a file from the net just use the WebClient class and its DownloadFile method

    0 讨论(0)
提交回复
热议问题