-1

I need help I can't deserialize my json

 var myWebClient = new WebClient();
 var js = new JavaScriptSerializer();
 var json = myWebClient.DownloadString("https://api.gdax.com/products/btc-usd/book?level=2");
 OrderBookContainerExmo container = js.Deserialize<OrderBookContainerExmo>(json);

I'm getting:

An unhandled exception of type 'System.Net.WebException' occurred in System.dll

Additional information:

The remote server returned an error: (400) Bad Request.

On this line:

var json = myWebClient.DownloadString("https://api.gdax.com/products/btc-usd/book?level=2");
Icet
  • 678
  • 2
  • 13
  • 31
Kmietek
  • 65
  • 2
  • 6
  • 2
    Have a look at the raw message using eg fiddler and you will see: `{"message":"User-Agent header is required."}` – stuartd Oct 24 '17 at 16:33

1 Answers1

0

As it was mentioned in comment, you need to add User-Agent to headers.

var myWebClient = new WebClient();
var js = new JavaScriptSerializer();
myWebClient.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)";
var json = myWebClient.DownloadString("https://api.gdax.com/products/btc-usd/book?level=2");
OrderBookContainerExmo container = js.Deserialize<OrderBookContainerExmo>(json);
Icet
  • 678
  • 2
  • 13
  • 31