Monday, 6 August 2018

C# REST Server POST and Get Response

async Task Main()
{
    string outputfile = "output.csv";
  
    File.Delete (outputfile);
  
    var httpWebRequest = (HttpWebRequest)WebRequest.Create(URL);
    httpWebRequest.ContentType = "application/json";
    httpWebRequest.Method = "POST";
  
    using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
    {
        string json = new JavaScriptSerializer().Serialize(new
        {
            startDate = "7/1/2018",
            endDate = "6/30/2019",
            codes = new string[] { "value1", "value2" },
            skus= "",
            returnCSV = 1
        });
        streamWriter.Write(json);
    }

    var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
    using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
    {
        using (StreamWriter sw = new StreamWriter(outputfile))
            sw.Write(await streamReader.ReadToEndAsync());
    }
}

No comments:

Setup Windows Local Account without the Internet

During the Windows setup,  On the WiFi screen, press SHIFT + F10  or  FN + SHIFT + F10  This will open the command prompt window with admini...