x
all questions login
General DNS & Domains Dyn Email Update Clients Dyn Developer

I'm trying to use the API to validate DynDNS credentials, and the documentation says that the 'badauth' response is meant for exactly that. Great! With that I can automate an update with some credentials and look for the badauth response and use that to detect incorrect credentials, sounds perfect.
The problem is that the only response I get is badauth. Even when I send credentials that should be good (since they're currently working 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() );
         }
       }

Any idea what I'm missing here?

more ▼

asked Nov 30 at 08:56 PM

Task\'s gravatar image

Task
31 1 1

10|600 characters needed characters left

2 answers:

Solution found!
In essence, the problem is Uri-embedded credentials. Don't use them!
Here's the code that fixed the problem entirely:

string target = string.Format( "http://members.dyndns.org:8245/nic/update?hostname={0}&myip={1}", HttpUtility.UrlEncode( DynDnsURL ), ip );
HttpWebRequest request = WebRequest.Create( target ) as HttpWebRequest;
request.Credentials = new NetworkCredential( DynDnsUserName, DynDnsPassword );

Even though WebRequest.Create accepts a Uri instance and Uri understands embedded credentials, HttpWebRequest.GetResponse obviously doesn't treat these two methods of specifying credentials equivalently because one works and the other doesn't.

more ▼

answered Dec 12 at 03:34 PM

Task\'s gravatar image

Task
31 1 1

10|600 characters needed characters left

I could imagine that you're locked out for a while if you attempted too many invalid authentications. You may have to wait several cups of coffee before it will work again with valid credentials.

more ▼

answered Dec 02 at 08:22 PM

RotBlitz\'s gravatar image

RotBlitz ♦
27.9k 4 14 94

I would imagine that if that were the problem I'd be getting the 'abuse' response instead of the 'badauth' response. It's definitely a 401 Unauthorized exception being thrown with 'badauth' in the response body.

Dec 05 at 07:21 PM Task
10|600 characters needed characters left
Your answer
osqa.question.ask.tags.preview.show

© 1998-2011  Dynamic Network Services Inc.  -  Legal Notices  -  Privacy Policy  -  Contacts     

Powered by Qato