我的代码中有以下简单的HttpWebRequest用于点击事件:(VS 2017)
public void Button_Clicked(object sender, EventArgs e)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://192.168.0.10/api/c3knn1r79DQY391tANlYD9u9Jlm4U5Ch54lqm2fd/lights/6/state");
request.ContentType = "application/x-www-form-urlencoded";
request.Method = "PUT";
request.BeginGetRequestStream(new AsyncCallback(GetRequestStreamCallback), request);
valueLabel.Text = "DONE";
}
public static void GetRequestStreamCallback(IAsyncResult asynchronousResult)
{
HttpWebRequest request = (HttpWebRequest)asynchronousResult.AsyncState;
Stream postStream = request.EndGetRequestStream(asynchronousResult);
string postData = "{\"on\":true}";
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
postStream.Write(byteArray, 0, postData.Length);
request.BeginGetResponse(new AsyncCallback(GetResponseCallback), request);
}
public static void GetResponseCallback(IAsyncResult asynchronousResult)
{
HttpWebRequest request = (HttpWebRequest)asynchronousResult.AsyncState;
Stream streamResponse = response.GetResponseStream();
StreamReader streamRead = new StreamReader(streamResponse);
string responseString = streamRead.ReadToEnd();
}
它似乎适用于我的visualstudio_andriod-23_x86。它打开了灯。但是,当我将其部署到我的Samsung Note 4设备时,什么也没发生。没有错误或什么也没有,没有灯亮。我在Android Manifest下添加了INTERNET的预授权。这是输出日志:
另外,我在日志中注意到: AOT模块' System.Net.Requests.dll.so'找不到:dlopen失败:library" /data/app/App2.Android-1/lib/arm/libaot-System.Net.Requests.dll.so"找不到
但是我在工作模拟器中得到了这个错误行。所以这不是问题。 有什么想法吗?请帮忙。谢谢
答案 0 :(得分:1)
好吧,花了好几个小时后我意识到我必须重置路由器。它现在正在运作