我只是想发布我的代码,我真的很对,Incase其他可能需要帮助它有一天!
为了简单起见,我已将它分解为一些子函数。不要让它吓到你。
/// <summary>
/// Call this from another class to update a zone.
/// </summary>
/// <param name="host">The full name of the host</param>
/// <returns></returns>
public string Update(String host)
{
string url = BuildUrl(host, Ip);
return PerformUpdate(url);
}
这里是构建URL
/// <summary>
/// //Constructs the url to send the get request to.
/// </summary>
/// <param name="hostname">the hostname </param>
/// <param name="ip">the ipaddress</param>
/// <returns>The complete String</returns>
private string BuildUrl(String hostname, String ip)
{
return BaseUrl + "hostname=" + hostname + "&myip=" + ip;
}
这里的功能是不更新的功能:
/// <summary>
/// Performs the actual request to the dyndns server to update the entity
/// </summary>
/// <param name="url">url to post</param>
private String PerformUpdate(String url)
{
HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
NetworkCredential creds = new NetworkCredential(Username, Password);
request.UserAgent = Username + " - " + Password + " - " + "0.01";
request.Credentials = creds;
request.Method = "GET";
HttpWebResponse response = request.GetResponse() as HttpWebResponse;
Stream reply = response.GetResponseStream();
StreamReader readReply = new StreamReader(reply);
return readReply.ReadToEnd();
}
你这是什么意思,“我该怎么办的主机名'? –
在示例中,他们拥有主持人members.dynds.org。在我的请求字符串中,我没有? – Zapnologica
不,但你有一些其他的主机名指向你的IP –