Toolbox.NETMF.NET.HTTP_Client

Toolbox.NETMF.NET.HTTP_Client(Socket)
  • Socket A reference for the socket to be used (see also: SimpleSocket)

Methods

  • Authenticate(Username, Password) Authenticates a user with HTTP Authentication
  • Get(Url, Arguments) Executes a GET request and returns a HTTP Response
  • Post(Url, Arguments) Executes a POST request and returns a HTTP Response
  • SetCookie(Key, Value) Sets a cookie

Properties

  • Accept Returns/sets the HTTP Accept-header
  • AcceptLanguage Returns/sets the HTTP AcceptLanguage-header
  • Hostname Returns the hostname of the webserver
  • Port Returns the TCP port of the webserver
  • Referrer Returns/sets the HTTP Referer-header

What if I get a System.OutOfMemoryException ?

This error message is both the downside and challenge of working with an embedded platform. There are some very creative solutions. Here are a few:
  • Modify the requested page
  • Check if there's an RSS feed of the page which could be smaller
  • Introduce yourself as a mobile device, some pages will send back a more compact version
For example, pretending to be an HTC HD2 running Opera, could be done by setting some headers:
WebSession.UserAgent = "HTC_HD2_T8585 Opera/9.7 (Windows NT 5.1; U; en)"
WebSession.Accept = "text/html; application/xml;q=0.9, application/xhtml+xml, image/png, image/jpeg, image/gif, image/x-bitmap, */*;q=0.1, application/youtube-client"
WebSession.AcceptLanguage = "en-US,en;q=0.9"

Sample code in C#

// Creates a new web session
HTTP_Client WebSession = new HTTP_Client(new IntegratedSocket("www.netmftoolbox.com", 80));

// Requests the latest source
HTTP_Client.HTTP_Response Response = WebSession.Get("/helloworld/");

// Did we get the expected response? (a "200 OK")
if (Response.ResponseCode != 200)
    throw new ApplicationException("Unexpected HTTP response code: " + Response.ResponseCode.ToString());

// Fetches a response header
Debug.Print("Current date according to www.netmftoolbox.com: " + Response.ResponseHeader("date"));

// Gets the response as a string
Debug.Print(Response.ToString());

Sample code in VB

' Creates a new web session
Dim WebSession As HTTP_Client = New HTTP_Client(new IntegratedSocket("www.netmftoolbox.com", 80))

' Requests the latest source
Dim Response As HTTP_Client.HTTP_Response = WebSession.Get("/helloworld/")

' Did we get the expected response? (a "200 OK")
If Response.ResponseCode <> 200 Then
    Throw New ApplicationException("Unexpected HTTP response code: " + Response.ResponseCode.ToString())
End If

' Fetches a response header
Debug.Print("Current date according to www.netmftoolbox.com: " + Response.ResponseHeader("date"))

' Gets the response as a string
Debug.Print(Response.ToString())

Last edited Feb 17, 2012 at 10:01 PM by Garrcomm, version 9