【发布时间】:2021-04-03 13:37:48
【问题描述】:
我正在做一个小项目来处理游戏中的一些大数据,这将使我能够查看一些高级分析,但是,我遇到了困难...... 以下 URL (Click Here) 是一个开放 API,它返回 JSON 结果,我正在尝试将其作为我自己的数据进行处理。
我已经创建了一个类,应该将这些数据处理到我的模型中,但是,每次调用第 5 行client.DownloadString 我都会收到错误 403,有什么办法解决这个问题吗? 我不知道 api 的所有者。
public IActionResult Index(object sender, EventArgs e)
{
var model = new FresnoVm();
WebClient client = new WebClient();
string strPageCode = client.DownloadString("https://api.upx.world/bigdata/query?neighborhood=210&neighborhood=359&neighborhood=367&neighborhood=366&neighborhood=356&neighborhood=364&city=0&status=All&mintMin=0&mintMax=100000000&saleMin=0&saleMax=100000000&skip=0&fsa=All&sort=mint_price&ascOrDesc=1");
dynamic dobj = JsonConvert.DeserializeObject<dynamic>(strPageCode);
price = dobj["data"]["properties"]["sale_price_upx"].ToString();
model.test = price;
return View("~/Features/Fresno/Index.cshtml", model);
}
【问题讨论】:
-
这能回答你的问题吗? WebClient 403 Forbidden
-
这与 403 错误无关,但如果您收到大于 85,000 字节的 JSON,您应该直接从响应流中反序列化它,而不是将其作为字符串下载并解析。直接从响应流中反序列化,如 e.g. newtonsoft.com/json/help/html/Performance.htm#MemoryUsage