简体   繁体   中英

How to send post url request and get response return file download into local directory in C# .net

Does anyone know how can I send a post request url and get response return file download into local directory in C# .net? I have the following code which manage to send a post url request and response with the zip file. how can I save the file into the directory?

    var client = new WebClient();

    var values = new NameValueCollection();
    values["StartDate"] = "18-Sep-2016 00:00";
    values["EndDate"] = "23-Sep-2016 00:00";
    values["CampaignName"] = "null";
    values["SearchBy"] = "Evaluation";
    values["CustomFilter"] = "rep.CALLDNIS like '#0400000000%'";


    var response = client.UploadValues("http://test.com", values);

    client.DownloadFile(response, @"C:\myfile.zip");

UploadValues returns a type of byte[] .

You can use System.IO.File.WriteAllBytes(filePath, response) to save it as a file.

OR

Check here How to zip (and unzip) byte[] in C#? on how to save it as a zip file.

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