0

I am new to C#, I want to make the following curl call in my C#(In perl i will directy use system call to mke curl request)

curl 'http://shop.nordstrom.com/soajax/storeavailability?postalCode=90067&radius=100' -H 'Origin: http://shop.nordstrom.com' -H 'Accept-Encoding: gzip, deflate' -H 'Accept-Language: en-US,en;q=0.8' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/49.0.2623.108 Chrome/49.0.2623.108 Safari/537.36' -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Referer: http://shop.nordstrom.com/s/cece-by-cynthia-steffe-jackie-cold-shoulder-fit-flare-dress/4261930' --data-binary '{"SameDayDeliveryStoreNumber":0,"styleSkus":[{"StyleId":4261930,"SkuIds":[32882914,32877390,32877377,32882917,32882922,32882926,32877379,32882887,32882891,32877382,32882897,32882902,32882907,32882909]}],"RefreshSameDayDeliveryStore":true}' --compressed

First how could i change all the parameters to http so i can view the response in my browser

Then Can I convert a cURL call to an HTTP request? If so, how? If not, how can I make the above cURL call from my C# program so i will get response properly?

Mounarajan
  • 1,357
  • 5
  • 22
  • 43

1 Answers1

1

Just make a HttpWebRequest :

var url = "http://shop.nordstrom.com/soajax/storeavailability?postalCode=90067&radius=100";
var request = (HttpWebRequest)WebRequest.Create(url);
request.Method = WebRequestMethods.Http.Post;
request.Headers["origin"] = "http://shop.nordstrom.com";
request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
request.Headers["Accept-Language"] = "en-US,en;q=0.8";
request.UserAgent = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/49.0.2623.108 Chrome/49.0.2623.108 Safari/537.36";
request.ContentType = "application/json";
request.Accept = "application/json";
request.Referer = "http://shop.nordstrom.com/s/cece-by-cynthia-steffe-jackie-cold-shoulder-fit-flare-dress/4261930";
using (var writer = new StreamWriter(request.GetRequestStream()))
{
    writer.Write("{\"SameDayDeliveryStoreNumber\":0,\"styleSkus\":[{\"StyleId\":4261930,\"SkuIds\":[32882914,32877390,32877377,32882917,32882922,32882926,32877379,32882887,32882891,32877382,32882897,32882902,32882907,32882909]}],\"RefreshSameDayDeliveryStore\":true}");
}

var response = request.GetResponse();
using (var reader = new StreamReader(response.GetResponseStream()))
{
    var json = reader.ReadToEnd();
    // do stuffs...
}
Xiaoy312
  • 14,292
  • 1
  • 32
  • 44