本文介绍了测试Discord邀请链接是否无效?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试制作一个用于测试Discord邀请链接并检查它们是否无效的应用程序.但是,我不知道该怎么做.
I am trying to make an application that tests Discord invite links and checks if they are invalid or valid. However, I do not know how to do this.
推荐答案
使用GET请求发送到邀请端点.
Use a GET request to the invite endpoint.
请求:
GET: https://discordapp.com/api/invite/obviously-invalid-invite-code
响应(HTTP状态404):
Response (HTTP status 404):
{
"code": 10006,
"message": "Unknown Invite"
}
您可以通过对终端使用 WebRequest
调用,并捕获在API返回404时抛出的 WebException
来实现.
You can do this by using a WebRequest
call to the endpoint, and catching a WebException
that gets thrown when the API returns 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;
}
这篇关于测试Discord邀请链接是否无效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!