Reputation: 3686
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?
Upvotes: 1
Views: 1357
Reputation: 2741
{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;
Upvotes: 2