0

I'm trying to integrate with Shopping.com REST service.
so I wrote a simple (minimum code) C# application to retrieve the XML data using HttpWebRequest class. I've used StopWatch for bench-marking and the response time (Including Stream.ReadToEnd()) is something like 1300-1700 milliseconds.

it might sound good, but then I've tested the response time in Chrome browser with Fiddler and the response time was about 600-800.

I've read few articles. some suggested set HttpWebRequest.Proxy to null / WebRequest.DefaultWebProxy but it didn't make significant improvement.

Here the request-url:
http://sandbox.api.shopping.com/publisher/3.0/rest/GeneralSearch?apiKey=78b0db8a-0ee1-4939-a2f9-d3cd95ec0fcc&trackingId=7000610&keyword=nikon

So, what should I do to reach this response time?

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Creativity Paralyze
  • 257
  • 1
  • 4
  • 14

1 Answers1

0

Are you enabling gzip and deflate?

Also, the first time you execute a web request in your code, there is a warmup to load the necessary assemblies, initialize the service point, and establish the HTTP connection, so be sure to look at the time for the second and subsequent executions.

EDIT: Sorry you will still need to decode the results using a GZipStream or DeflateStream, but this at least gives you the idea. See here for more info: HttpWebRequest & Native GZip Compression

var timer = Stopwatch.StartNew();

var url = "http://sandbox.api.shopping.com/publisher/3.0/rest/GeneralSearch?apiKey=78b0db8a-0ee1-4939-a2f9-d3cd95ec0fcc&trackingId=7000610&keyword=nikon";
var webRequest = WebRequest.Create(url);
webRequest.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip, deflate");
using (var webResponse = webRequest.GetResponse())
using (var responseStream = webResponse.GetResponseStream())
using (var streamReader = new StreamReader(responseStream))
{
    var content = streamReader.ReadToEnd();
}

var timeSpan = timer.Elapsed;
Console.WriteLine(timeSpan);
Community
  • 1
  • 1
Steven Padfield
  • 644
  • 1
  • 5
  • 12