C# 为什么我一直用C从我的webrequest代码中获取401#

C# 为什么我一直用C从我的webrequest代码中获取401#,c#,C#,如果我使用一个常规的url,它可以正常工作,如果我使用谷歌域名更新url,我会得到401错误。这是我第一次尝试C#应用程序 HttpWebRequest request = WebRequest.Create("https://UUUUUUUUUUUUU:PPPPPPPPPPPPP@domains.google.com/nic/update?hostname=subdomain.example.com") as HttpWebRequest; //request

如果我使用一个常规的url,它可以正常工作,如果我使用谷歌域名更新url,我会得到401错误。这是我第一次尝试C#应用程序

        HttpWebRequest request = WebRequest.Create("https://UUUUUUUUUUUUU:PPPPPPPPPPPPP@domains.google.com/nic/update?hostname=subdomain.example.com") as HttpWebRequest;

        //request.Accept = "application/xrds+xml";  
        request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.102 Safari/537.36 Viv/1.97.1246.7";
        request.UseDefaultCredentials = true;
        request.PreAuthenticate = true;
        request.Credentials = CredentialCache.DefaultCredentials;
        HttpWebResponse response = (HttpWebResponse)request.GetResponse();

        WebHeaderCollection header = response.Headers;

        var encoding = ASCIIEncoding.ASCII;
        using (var reader = new System.IO.StreamReader(response.GetResponseStream(), encoding))
        {
            string responseText = reader.ReadToEnd();
            //responseddns = responseText;
            MessageBox.Show(responseText);
        }
如果我使用它工作正常,我可以看到输出。

您不能使用它

> `CredentialCache.DefaultCredentials;`
因为url是domain.google.com的域。 您需要输入您的google凭据,否则直接使用
正如你以前所做的那样,401用于未经授权的访问。确保您正在访问公开可用的url。还要确保您的url存在,并且您可以在浏览器中访问它。我正在正确使用凭据,我只是删除了用户名和密码,以便在此处发布。如果我直接在浏览器中使用url,它可以正常工作,如果我在c#中使用准确的url,我会得到错误401。