我有這個hardware來自Patlite, 這個硬件有一個HTTP命令控制功能,例如,如果我複製網址「http://192.168.10.1/api/control?alert=101002」在我的電腦中鍍鉻,它將根據需要激活硬件。c#如何發送HTTP命令,因爲這 - http://192.168.10.1/api/control?alert=101002
我想從我的代碼發送命令。
我想這個代碼沒有運氣:
System.Net.ServicePointManager.Expect100Continue = false;
WebRequest request = WebRequest.Create("http://10.0.22.222/api/control");
request.Method = "post";
request.ContentType = "application/x-www-form-urlencoded";
string postData = "alert=101002";
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
request.ContentLength = byteArray.Length;
// Get the request stream.
Stream dataStream = request.GetRequestStream();
// Write the data to the request stream.
dataStream.Write(byteArray, 0, byteArray.Length);
// Close the Stream object.
dataStream.Close();
WebResponse response = request.GetResponse();
感謝
「我試過這段代碼沒有運氣」發生了什麼事? – Oscar