1
我正在嘗試使用DynDNS API來驗證用戶提供的DynDNS憑據,並且the documentation說the 'badauth' response只能用於此目的。
這個想法是,我可以使用用戶憑據自動更新並查找badauth響應並使用它來檢測不正確的憑據,這聽起來很完美。
問題是我得到的唯一答案是badauth。當我發送應該是好的憑據(因爲他們目前正在登錄和所有工作),我得到一個badauth響應。這裏是我的代碼:與badauth的響應體:DynDNS和無可爭議的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)未經授權的遠程服務器返回錯誤」。有任何想法嗎?
嗯,在[URI](http://msdn.microsoft.com/ en-us/library/system.uri.userinfo.aspx)類和[WebRequest.Create](http://msdn.microsoft.com/en-us/library/0aa3d588.aspx)方法建議它應該工作,但這可能是我的錯誤假設。我會研究一下,謝謝。 – Task
太棒了,你絕對正確!儘管API文檔本身一直使用Uri-embedded-credentials方法,但它實際上並不工作。切換到指定憑證的更具體的方法使所有的工作都很完美。 – Task
就在幾周前有這個問題。 – Sandman4