DynDNS API を使用して、ユーザーが指定した DynDNS 資格情報を検証しようとしていますが、ドキュメントによると、「badauth」応答はまさにそのためのものです。
ユーザー資格情報を使用して更新を自動化し、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() );
}
}
使用する資格情報に関係なく、「リモートサーバーがエラーを返しました: (401) Unauthorized」という WebException がスローされ、応答本文が badauth になります。何か案は?