Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/297.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 用C在noip.com上重新加载IP#_C#_Post_Web_Request_Ip - Fatal编程技术网

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

C# 用C在noip.com上重新加载IP#,c#,post,web,request,ip,C#,Post,Web,Request,Ip,无法将POST请求发送到正确的站点:noip.com。 . 正在尝试将请求发布到C#: 您可以尝试以下方法: public static void DynamicUpdate(string hostname, string myip, string username, string password) { try { HttpWebRequest req = (HttpWebRequest)

无法将POST请求发送到正确的站点:noip.com。 . 正在尝试将请求发布到C#:

您可以尝试以下方法:

    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
        {
        }
    }

:)

您可以在.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 {

        }
    }

您试图同时发出POST和GET请求?。“Zapros”变量的内容实际上是请求的内容和设置,而不是请求正文中应有的内容。如果将request.Method更改为“GET”,那么请求对象应该具有可以分配的主机和授权部分。(对于用户代理也是如此)。
    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 {

        }
    }