对邀请端点使用 GET 请求。
要求:
GET: https://discordapp.com/api/invite/obviously-invalid-invite-code
Run Code Online (Sandbox Code Playgroud)
响应(HTTP 状态 404):
{
"code": 10006,
"message": "Unknown Invite"
}
Run Code Online (Sandbox Code Playgroud)
您可以通过WebRequest调用端点并捕获WebExceptionAPI 返回 404 时抛出的异常来完成此操作。
try
{
WebRequest request = WebRequest.Create("https://discordapp.com/api/invites/obviously-invalid-invite-code");
request.Method = "GET";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
if (response.StatusCode == HttpStatusCode.OK) // and possibly other checks in the response contents
{
Console.WriteLine("Invite link is valid");
}
}
catch (WebException wex)
{
if (((HttpWebResponse)wex.Response).StatusCode == HttpStatusCode.NotFound)
{
Console.WriteLine("Invite link is invalid");
}
// You may need to account for other 400/500 statuses
else throw wex;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7252 次 |
| 最近记录: |