DynDNS 和无可争议的 badauth 响应
我正在尝试使用 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
{0}:{1}@... 不适用于网络请求。
你的目标只是“http://members.dynd....”,你做了类似的事情
{0}:{1}@... won't do with webrequest.
Your target is just "http://members.dynd....", and you do something like