DynDNS 和无可争议的 badauth 响应

发布于 2024-12-20 01:51:06 字数 1640 浏览 5 评论 0原文

我正在尝试使用 DynDNS API 来验证用户提供的 DynDNS 凭据,以及文档 表示 “badauth”响应 的目的正是那个。
我的想法是,我可以使用用户凭据自动更新,并查找 badauth 响应,并使用它来检测不正确的凭据,这听起来很完美。
问题是我得到的唯一回应是 badauth。当我发送应该很好的凭据时(因为它们当前正在用于登录等),我收到了错误响应。这是我的代码:

   try
   {
     string target = string.Format( "http://{0}:{1}@members.dyndns.org:8245/nic/update?hostname={2}&myip={3}",
      HttpUtility.UrlEncode( DynDnsUserName ), HttpUtility.UrlEncode( DynDnsPassword ), HttpUtility.UrlEncode( DynDnsURL ), ip );
     HttpWebRequest request = WebRequest.Create( target ) as HttpWebRequest;
     request.Method = "GET";
     request.UserAgent = company + " - " + model + " - " + firmware;
     HttpWebResponse response = request.GetResponse() as HttpWebResponse;
     Stream reply = response.GetResponseStream();
     StreamReader readReply = new StreamReader( reply );
     string returnCode = readReply.ReadToEnd();
     Trace.WriteLine( "We've validated the provided DynDNS credentials, response received: " + returnCode );
     return !returnCode.Contains( "badauth" );
   }
   catch (WebException webEx)
   {
     Trace.WriteLine( "WebException thrown: " + webEx.Message );
     if (webEx.Response != null)
     {
      Stream reply = webEx.Response.GetResponseStream();
      StreamReader readReply = new StreamReader( reply );
      Trace.WriteLine( "Actual response: " + readReply.ReadToEnd() );
     }
   }

无论我使用什么凭据,我都会不断收到抛出的 WebException“远程服务器返回错误:(401) 未经授权”,响应正文为 badauth。有什么想法吗?

I'm trying to use the DynDNS API to validate user-supplied DynDNS credentials, and the documentation says that the 'badauth' response is meant for exactly that.
The idea being that I can automate an update with the user credentials and look for the badauth response and use that to detect incorrect credentials, which sounds perfect.
The problem is that the only response I ever get is badauth. When I send credentials that should be good (since they're currently working for login and all) I get a badauth response. Here's my code:

   try
   {
     string target = string.Format( "http://{0}:{1}@members.dyndns.org:8245/nic/update?hostname={2}&myip={3}",
      HttpUtility.UrlEncode( DynDnsUserName ), HttpUtility.UrlEncode( DynDnsPassword ), HttpUtility.UrlEncode( DynDnsURL ), ip );
     HttpWebRequest request = WebRequest.Create( target ) as HttpWebRequest;
     request.Method = "GET";
     request.UserAgent = company + " - " + model + " - " + firmware;
     HttpWebResponse response = request.GetResponse() as HttpWebResponse;
     Stream reply = response.GetResponseStream();
     StreamReader readReply = new StreamReader( reply );
     string returnCode = readReply.ReadToEnd();
     Trace.WriteLine( "We've validated the provided DynDNS credentials, response received: " + returnCode );
     return !returnCode.Contains( "badauth" );
   }
   catch (WebException webEx)
   {
     Trace.WriteLine( "WebException thrown: " + webEx.Message );
     if (webEx.Response != null)
     {
      Stream reply = webEx.Response.GetResponseStream();
      StreamReader readReply = new StreamReader( reply );
      Trace.WriteLine( "Actual response: " + readReply.ReadToEnd() );
     }
   }

No matter the credentials I use, I keep getting a thrown WebException "Remote server returned an error: (401) Unauthorized" with a response body of badauth. Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

本宫微胖 2024-12-27 01:51:06

{0}:{1}@... 不适用于网络请求。

你的目标只是“http://members.dynd....”,你做了类似的事情

NetworkCredential myCredentials = new NetworkCredential(username,passwd);

request.Credentials = myCredentials;

{0}:{1}@... won't do with webrequest.

Your target is just "http://members.dynd....", and you do something like

NetworkCredential myCredentials = new NetworkCredential(username,passwd);

request.Credentials = myCredentials;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文