在 C# 中重新加载 noip.com 上的 IP

本文关键字:noip com 上的 IP 加载 新加载 | 更新日期: 2023-09-27 18:32:19

不可能

向正确的站点发送 POST 请求:noip.com。此处包含的说明。正在尝试向 C# 发出 POST 请求:

private void DDD()
        {
            string Host = "";
            string Authorization = "";
            string Authorization_Base64 = Convert.ToBase64String(Encoding.UTF8.GetBytes(Authorization));
            string Zapros = "GET /nic/update?hostname=" + Host + "&myip=1.2.3.4 HTTP/1.0" + "'n"
                + "Host: dynupdate.no-ip.com" + "'n"
                + "Authorization: " + Authorization_Base64 + "'n"
                + "User-Agent: MSA/1.0 msa.com";
            System.Net.HttpWebRequest reqPOST = (HttpWebRequest)WebRequest.Create("http://dynupdate.no-ip.com/nic/update");
            reqPOST.Method = "POST"; 
            reqPOST.Timeout = 120000; 
            byte[] sentData = Encoding.UTF8.GetBytes(Zapros);
            reqPOST.ContentLength = sentData.Length;
            System.IO.Stream sendStream = reqPOST.GetRequestStream();
            sendStream.Write(sentData, 0, sentData.Length);
            sendStream.Close();
            System.Net.WebResponse result = reqPOST.GetResponse();
            System.IO.Stream stream = result.GetResponseStream();
            System.IO.StreamReader sr = new System.IO.StreamReader(stream);
            string s = sr.ReadToEnd();
            MessageBox.Show(s);
        }

在 C# 中重新加载 noip.com 上的 IP

您可以在 .NET 4.5 中使用 HttpClient:

    public static async void DynamicUpdate(string hostname, string myip, string username, string password) {
        try {
            string noipuri = "http://dynupdate.no-ip.com/nic/update?hostname=" + hostname + "&myip=" + myip;
            using (var client = new HttpClient(new HttpClientHandler { Credentials = new NetworkCredential(username, password) }))
            using (var response = await client.GetAsync(noipuri))
            using (var content = response.Content) {
                await content.ReadAsStringAsync();
            }
        }
        catch {
        }
    }

你可以试试这个:

    public static void DynamicUpdate(string hostname, string myip, string username, string password)
    {
        try
        {
            HttpWebRequest req =
                (HttpWebRequest)
                    HttpWebRequest.Create("http://dynupdate.no-ip.com/nic/update?hostname=" + hostname + "&myip=" + myip);
            req.Host = "dynupdate.no-ip.com";
            req.Credentials = new NetworkCredential(username, password);
            req.UserAgent = "My awesome update Client/1.0 contact@email.com";
            req.Method = "GET";
            using (var res = (HttpWebResponse)req.GetResponse())
            {
                // Do something with the response accordingly to
                // http://www.noip.com/integrate/response
            }
        }
        catch
        {
        }
    }

:)