NHttpLib is a NewtonScript unit for making HTTP connections. It can be used on any NIE 2.0 capable Newton device.
Code using this proto looks like this:
Note: When fetching an URL, the opening of the Connection Slip before making a connection can be suppressed by setting
Handle Incoming Data
This code however would not do anything with the incoming data. It is also important to know that NHttpLib ''does not'' store the incoming data! To handle the different possible content types, the array
where the contentTypes slot is an array of strings representing the handled content type like "text/html" or "text/xml" as returned by the HTTP server. It is also possible to specify "*" as a wildcard for any content type. The spec frame is an inputSpec that describes how to receive the data. A simple example that just prints out incoming HTML or XML data looks like this:
Basically, an application should just have to implement the
To handle the successful termination of a transmission, it is also possible to specify the
Before the body of the HTTP request is processed, the HTTP header fields are already available in the FSM frame. They can be accessed through the
The return value of the
The NHttpLib unit installs a new settings editor in the ''Internet Setup'' application. It can be used to add an HTTP proxy to an internet setup. The format of the proxy setting string can be any valid url, e.g. "192.168.1.1:8000".
Cookies are stored in the soup "NHttpLib Cookies" if fStoreCookies is set to true in the base frame. Cookies are sent if fSendCookies is set to true. By default, cookie saving and sending is enabled.
The Fetch URL Transport
NHttpLib adds a simple transport to the Inbox that allows downloading of URLs into the Inbox. After installing NHttpLib, a new menu item "Fetch URL" is added to the "Receive" picker in the Inbox. NHttpLib saves the downloaded data in the Inbox soup with this format:
Version 2.0 is a complete rewrite of the library. It is a simpler design than the previous versions which were based on protoFSM. This version explicitly hard-codes the steps needed to grab a link, bind and connect an endpoint, transfer data and close the connection. It is implemented as a proto and should be assigned to a _proto slot in a frame.
Thanks to Ken Hagler, Grant Hutchinson, Patrick Clark, Frank Gruendel and Marcus Schneider for testing!
Bugs and To Do's
Cancelling operations via the Stop button in the status view seems cause instabilties at some times (timeouts are working better). Closing a connection is slow.
Setting the fEndpointEncoding to a value different from nil causes problems (the kPCRomanEncoding is not implemented on US MessagePads).