0

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");
Jin Yong
  • 42,698
  • 72
  • 141
  • 187
  • possible duplicate of http://stackoverflow.com/questions/10801681/downloading-a-file-via-an-http-post-where-am-i-going-wrong – Mitz Sep 23 '16 at 06:02

1 Answers1

1

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.

Community
  • 1
  • 1
Oluwafemi
  • 14,243
  • 11
  • 43
  • 59