【发布时间】:2014-11-26 18:49:02
【问题描述】:
无法将 POST 请求发送到正确的站点:noip.com。 Instructions contained here。 尝试向 C# 发送请求:
private void DDD()
{
string Host = "";
string Authorization = "";
string Authorization_Base64 = Convert.ToBase64String(Encoding.UTF8.GetBytes(Authorization));
string Zapros = "GET /nic/update?hostname=" + Host + "&myip=1.2.3.4 HTTP/1.0" + "\n"
+ "Host: dynupdate.no-ip.com" + "\n"
+ "Authorization: " + Authorization_Base64 + "\n"
+ "User-Agent: MSA/1.0 msa.com";
System.Net.HttpWebRequest reqPOST = (HttpWebRequest)WebRequest.Create("http://dynupdate.no-ip.com/nic/update");
reqPOST.Method = "POST";
reqPOST.Timeout = 120000;
byte[] sentData = Encoding.UTF8.GetBytes(Zapros);
reqPOST.ContentLength = sentData.Length;
System.IO.Stream sendStream = reqPOST.GetRequestStream();
sendStream.Write(sentData, 0, sentData.Length);
sendStream.Close();
System.Net.WebResponse result = reqPOST.GetResponse();
System.IO.Stream stream = result.GetResponseStream();
System.IO.StreamReader sr = new System.IO.StreamReader(stream);
string s = sr.ReadToEnd();
MessageBox.Show(s);
}
【问题讨论】:
-
您要同时发出 POST 和 GET 请求?您的“Zapros”变量的内容实际上是您的请求的内容和设置,而不是您的请求正文中应该包含的内容。如果您将 request.Method 更改为“GET”,那么请求对象应该具有您可以分配的主机和授权部分。 (以及用户代理)。