【发布时间】:2022-03-23 19:58:59
【问题描述】:
大家好,
我的代码有问题。大约一周以来,我的代码在没有任何更改的情况下不再工作。我很确定,我的能力应该可以工作。我得到的只是错误 404:禁止。 下面是我的代码的 sn-p。我还阅读了有关添加 webclient 的标头的信息,但没有帮助。还有其他建议吗?如果我的语法不是很好,我很抱歉,这是我在 stackoverflow 上的第一篇文章。提前致谢!
string epicId = "ManuelNotManni";
WebClient webClient = new WebClient();
Uri uri = new Uri("https://api.tracker.gg/api/v2/rocket-league/standard/profile/epic/");
string result = String.Empty;
try
{
string website = $"{uri.ToString()}{epicId}?";
result = webClient.DownloadString(website);
}
catch (Exception ex)
{
Console.WriteLine($"Error:\n{ex}");
Console.ReadLine();
}
finally
{
webClient.Dispose();
}
这是确切的错误:
System.Net.WebException:远程服务器返回错误:(403)禁止。 在 System.Net.HttpWebRequest.GetResponse() 在 System.Net.WebClient.GetWebResponse(WebRequest 请求) 在 System.Net.WebClient.DownloadBits(WebRequest 请求,流 writeStream) 在 System.Net.WebClient.DownloadDataInternal(Uri 地址,WebRequest& 请求) 在 System.Net.WebClient.DownloadString(Uri 地址) 在 System.Net.WebClient.DownloadString(字符串地址) 在 TestProject.Program.Main(String[] args) in > C:\Users\Manue\source\repos\TestProject\Program.cs:line 17
【问题讨论】:
-
看起来 API 不允许在没有任何凭据的情况下调用此 API。那就是你得到这个错误。您需要查看 API 文档和 API 支持以了解需要哪些凭据以及如何传递它们。