-1

我需要帮助我无法反序列化我的 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);

我越来越:

System.dll 中出现“System.Net.WebException”类型的未处理异常

附加信息:

远程服务器返回错误:(400) 错误请求。

在这条线上:

var json = myWebClient.DownloadString("https://api.gdax.com/products/btc-usd/book?level=2");
4

1 回答 1

0

正如评论中提到的,您需要将 User-Agent 添加到标题中。

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);
于 2017-10-26T13:32:28.597 回答