短信签名快速报备,马上注册寻求客户经理支持!
所有文档
运营商信息核验
文档中心 > 运营商信息核验 > 空号检测

空号检测

C#对接空号检测提交接口接口DEMO示例
本文为您提供了C#语言版本的空号检测提交接口接口对接DEMO示例

using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Net;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
using System.Text.Json;

class Program
{
    private const string host = "https://api.ihuyi.com";
    private const string path = "/empty-number/submit";
    private const string method = "POST";

    static void Main(string[] args)
    {
        // 定义请求的数据
        var values = new Dictionary<string, object>
        {
                {"mobiles": new List<string> { "18800000000", "18800000001" }}, //手机号数组(最多10个)
        };

        // 将数据转换为JSON字符串
        string jsonBody = JsonSerializer.Serialize(values);
        byte[] data = Encoding.UTF8.GetBytes(jsonBody);

        string url = host + path;
        HttpWebRequest httpRequest = null;
        HttpWebResponse httpResponse = null;

        if (host.Contains("https://"))
        {
            ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
            httpRequest = (HttpWebRequest)WebRequest.CreateDefault(new Uri(url));
        }
        else
        {
            httpRequest = (HttpWebRequest)WebRequest.Create(url);
        }
        
        httpRequest.Method = method;
        httpRequest.ContentType = "application/json";
        httpRequest.Data = "Tue, 26 Aug 2025 07:14:23 GMT"; // 请替换为当前的GMT时间
        httpRequest.Authorization = "Signature xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; //请替换为您的鉴权签名
        httpRequest.ContentLength = data.Length;
        
        // 将JSON数据写入请求体
        using (Stream stream = httpRequest.GetRequestStream())
        {
            stream.Write(data, 0, data.Length);
        }
        
        try
        {
            httpResponse = (HttpWebResponse)httpRequest.GetResponse();
        }
        catch (WebException ex)
        {
            httpResponse = (HttpWebResponse)ex.Response;
        }

        Console.WriteLine(httpResponse.StatusCode);
        Console.WriteLine(httpResponse.Method);
        Console.WriteLine(httpResponse.Headers);
        Stream st = httpResponse.GetResponseStream();
        StreamReader reader = new StreamReader(st, Encoding.GetEncoding("utf-8"));
        Console.WriteLine(reader.ReadToEnd());
        Console.WriteLine("\n");

        // 释放资源
        reader.Close();
        st.Close();
        if (httpResponse != null) 
            httpResponse.Close();
    }

    public static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
    {
        return true;
    }
}

在线咨询
服务热线:
4008 808 898

免费体验

提交成功
若短信发送异常,系统将自动给您发送语音验证码,请注意接听电话。

填写验证码后,点击“开通体验账户”自动开通体验账户。

收不到短信验证码?
×