[Netduino系列教程]连接到网络
本帖最后由 奈何col 于 2013-10-16 00:30 编辑占坑
//OpenJumper Netduino Ethernet
//www.openjumper.com
using System;
using Microsoft.SPOT;
using System.Net;
using System.IO;
using System.Threading;
using System.Text;
namespace MF_HttpTest
{
public class Program
{
public static void Main()
{
while (true)
{
Debug.Print(new string(System.Text.UTF8Encoding.UTF8.GetChars(getHttpData("http://www.baidu.com"))));
Thread.Sleep(10000);
}
}
static private byte[] getHttpData(string url)
{
HttpWebRequest request = HttpWebRequest.Create(url) as HttpWebRequest;
request.HttpsAuthentCerts = null;
request.KeepAlive = true;
WebResponse resp = null;
Stream respStream = null;
byte[] bytData = null;
try
{
resp = request.GetResponse();
}
catch (Exception e)
{
Debug.Print("Exception in HttpWebRequest.GetResponse(): " + e.Message.ToString());
return null;
}
if (resp != null)
{
respStream = resp.GetResponseStream();
int bytesRead = 0;
int totalBytes = 0;
respStream.ReadTimeout = 5000;
Debug.Print("resp length= " + resp.ContentLength.ToString());
if (resp.ContentLength != -1)
{
bytData = new byte;
while (totalBytes < bytData.Length)
{
bytesRead = respStream.Read(bytData, totalBytes, bytData.Length - totalBytes);
if (bytesRead == 0)
{
Debug.Print("Error: Received " + totalBytes.ToString() + " Out of " + bytData.Length.ToString());
bytData = null;
break;
}
totalBytes += bytesRead;
Debug.Print("Bytes Read Now 0: " + bytesRead + " Total: " + totalBytes);
}
return bytData;
}
}
if (respStream != null) respStream.Close();
if (resp != null) resp.Close();
request = null;
return bytData;
}
}
}
楼主有没有arduino连接网络的教程,或者是扫描网页内容之类的。。。
页:
[1]