[英]ASP.NET Core Email Validation with API
I am trying to validate an email whether it is real or fake.我正在尝试验证 email 是真的还是假的。 I am using some code but it always returns Ok .
我正在使用一些代码,但它总是返回Ok 。
This is my code:这是我的代码:
public string validateEmail(string userEmail)
{
try
{
string key = "xxxx";
string email = "xxxx";
var crmUrl = "https://app.emaillistvalidation.com/api/verifEmail?secret=" + key + "&email=" + email;
string url = crmUrl;
var client = new RestClient(url);
client.RemoteCertificateValidationCallback = new RemoteCertificateValidationCallback((sender, certificate, chain, policyErrors) => { return true; });
var request = new RestRequest();
request.AddHeader("authorization", "Basic xxxxxxxxxxxxxxxxxx");
IRestResponse response = client.Execute(request);
var content = response.Content;
return content;
}
catch (Exception ex)
{
}
return default;
}
What is wrong here?这里有什么问题? And what can I do instead?
而我能做些什么呢?
I am trying to validate an email whether it is real or fake.
我正在尝试验证 email 是真的还是假的。 I am using some code but it always returns Ok.
我正在使用一些代码,但它总是返回 Ok。
Well I have gone through the code and the API
You have shared.好吧,我已经浏览了代码和您共享的
API
。 I also register and open a demo api on https://app.emaillistvalidation.com/api
and its behaving as expected for both valid
and invalid
email.我还在
https://app.emaillistvalidation.com/api
上注册并打开了一个演示 api 及其对valid
和invalid
email 的预期行为。 Here are my steps:这是我的步骤:
Register on app.emaillistvalidation.com在 app.emaillistvalidation.com 上注册
My Controller Code我的 Controller 代码
[Route("ValidateEmail")]
[HttpGet]
public async Task<IActionResult> ValidateEmail(string emailId)
{
var handler = new HttpClientHandler();
var data = "";
handler.ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) => { return true; };
var client = new HttpClient(handler);
client.DefaultRequestHeaders.Accept.Clear();
var responseFromApi = await client.GetAsync("https://app.emaillistvalidation.com/api/verifEmail?secret=" + apiSecret + "&email=" + emailId + "");
if (responseFromApi.IsSuccessStatusCode)
{
data = await responseFromApi.Content.ReadAsStringAsync();
}
return Ok(data);
}
Output For Valid & Invalid Email Output 用于有效和无效 Email
Postman Direct Test Postman 直接测试
I have also tested on postman
for valid
email I got ok
response and for invalid
and wrong
email I got unknown
and disable
response.:我还在
postman
上测试了valid
的ok
我得到了正确的响应,对于invalid
和wrong
的 email 我得到了unknown
和disable
响应:
Wrong Email: Email 错误:
Wrong Domain:错误的域:
Note: Please double check the way you are trying.注意:请仔细检查您尝试的方式。 You could have a look on my code and the way I have tested.
你可以看看我的代码和我测试的方式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.