friendev EtherDune TCP/IP library
|
Provides an easy way to query a web server. More...
#include <HTTPClient.h>
Public Member Functions | |
HTTPClient () | |
~HTTPClient () | |
void | request (const String &hostName, const String &resource, uint16_t port=80) |
Starts a new HTTP request. More... | |
virtual void | onResponseReceived () |
Called immediately after the first line is received and there is a status code, e.g. More... | |
virtual void | onHeaderReceived (uint16_t len, const byte *data) |
Called once for each fragment of the header portion of the response More... | |
virtual void | onBodyReceived (uint16_t len, const byte *data) |
Called once for each fragment of the body that is received. More... | |
virtual void | onBodyBegin () |
Called when all HTTP headers have been received and the body of the response is about to arrive. More... | |
virtual void | onResponseEnd () |
Called after all the body has been received More... | |
![]() | |
TCPSocket () | |
void | connect () |
Initiates a TCP connection to remoteIP and remotePort. More... | |
void | close () |
Attempts to gracefully close a connection. More... | |
void | terminate () |
Immediately shuts down the socket and makes it available for a new task. More... | |
void | listen () |
Starts listening on the local port indicated by the localPort property. More... | |
void | accept () |
Accepts a connection request that has been received on the port this instance was listening on More... | |
void | accept (TCPSocket &listener) |
Accepts a connection request that was sent to another TCPSocket instance. More... | |
void | push () |
Sets the PSH TCP flag and also sends data in the outgoing buffer immediately. More... | |
virtual void | onConnectRequest () |
Called when a listening socket receives a connection request. More... | |
virtual void | onTerminate () |
Called when the socket is ready to be reused. More... | |
![]() | |
uint16_t | write (uint16_t len, const byte *data) |
In the case of TCP, writes the given data buffer to the socket. More... | |
uint16_t | write (const String &s) |
In the case of TCP, writes the given String to the socket, not including the null-terminating character. More... | |
uint16_t | write (const __FlashStringHelper *pattern,...) |
Writes out the specified PROGMEM string that may contain the % escape character. More... | |
template<class T > | |
uint16_t | write (const T &message) |
Writes out the binary representation of the parameter to the socket. More... | |
![]() | |
uint8_t | getState () |
Public Attributes | |
uint16_t | statusCode |
Contains the HTTP status code of the response. More... | |
![]() | |
nint16_t | remotePort |
remote TCP or UDP port More... | |
nint16_t | localPort |
local TCP or UDP port More... | |
IPAddress | remoteIP |
remote IP address to connect to (TCP) or send the next packet to (UDP) More... | |
Protected Attributes | |
FlowScanner | scanner |
Internal FlowScanner instance used to detect header/response/status code, etc. More... | |
![]() | |
SharedBuffer | buffer |
output buffer for this socket More... | |
![]() | |
uint8_t | stateTimer |
state timer, in ticks More... | |
uint8_t | state |
state code More... | |
Additional Inherited Members | |
![]() | |
void | prepareIPPacket () |
![]() | |
NetworkService () | |
~NetworkService () | |
![]() | |
void | setState (uint8_t newState, uint8_t timeout) |
Changes to a new state More... | |
![]() | |
static uint16_t | calcPseudoHeaderChecksum (uint8_t protocol, uint16_t length) |
Calculates the TCP or UDP pseudo header checksum. More... | |
static uint16_t | calcTCPChecksum (bool options, uint16_t dataLength, uint16_t dataChecksum) |
Calculates the TCP checksum. More... | |
static uint16_t | calcUDPChecksum (uint16_t dataLength, uint16_t dataChecksum) |
Calculates the UDP checksum. More... | |
static bool | verifyUDPTCPChecksum () |
Verifies if the UDP or TCP checksum of the current packet is correct. More... | |
![]() | |
static bool | sendIPPacket (uint16_t length) |
Puts the current in-memory packet in the network More... | |
static void | prepareIPPacket (const IPAddress &remoteIP) |
Sets up common IP header values for all outgoing IP packets and calculates the IP header checksum More... | |
static bool | sameLAN (IPAddress &dst) |
Determines whether the given IP is in the same subnet as localIP More... | |
static bool | begin (uint8_t cspin) |
Initializes EtherDune and the underlying hardware More... | |
static void | loop () |
Gives processing time to EtherDune so that it can check for incoming packets or send queued packets. More... | |
static DNSClient & | DNS () |
Obtains access to the DNS service singleton instance. More... | |
![]() | |
static void | writeByte (byte b) |
static void | writeByte (uint16_t dst, byte b) |
static void | writeBuf (uint16_t dst, uint16_t len, const byte *data) |
static void | writeBuf (uint16_t len, const byte *data) |
static uint16_t | hardwareChecksum (uint16_t src, uint16_t len) |
static uint16_t | hardwareChecksumRxOffset (uint16_t offset, uint16_t len) |
static void | moveMem (uint16_t dest, uint16_t src, uint16_t len) |
static void | readBuf (uint16_t src, uint16_t len, byte *data) |
static void | readBuf (uint16_t len, byte *data) |
static byte | readByte (uint16_t src) |
static void | packetSend (uint16_t len) |
static void | packetSend (uint16_t len, const byte *data) |
static void | loadSample () |
static void | loadAll () |
static void | release () |
static uint8_t | begin (uint8_t cspin) |
static void | loop () |
static void | enableBroadcast () |
static bool | isLinkUp () |
Determines whether the network link is ready More... | |
![]() | |
static uint8_t | srcPort_L_count = 0 |
self-incrementing counter for local ports. More... | |
![]() | |
static EthBuffer | packet |
in-memory packet buffer currently being processed. More... | |
static ARPService | ARP |
ARP singleton instance. More... | |
static MACAddress | localMAC |
Ethernet MAC address. More... | |
static IPAddress | localIP = { 0, 0, 0, 0 } |
IP address of this application. More... | |
static IPAddress | gatewayIP = { 0, 0, 0, 0 } |
IP address of the gateway in this network. More... | |
static IPAddress | netmask = { 0, 0, 0, 0 } |
Subnet mask. More... | |
static IPAddress | dnsIP = { 0, 0, 0, 0 } |
IP address of the DNS server to use. More... | |
Provides an easy way to query a web server.
This class extends TCPSocket by adding methods that are helpful when connecting to a web server.
To use this class, create a derived class and override the appropriate virtual functions to receive notifications about the progress of the request and capture the needed data for your application
The flow of calls works as follows:
200 OK
See HTTPClientDemo_REST.ino for a full example on how to use this class.
Definition at line 41 of file HTTPClient.h.
HTTPClient::HTTPClient | ( | ) |
Definition at line 53 of file HTTPClient.cpp.
HTTPClient::~HTTPClient | ( | ) |
Definition at line 159 of file HTTPClient.cpp.
|
virtual |
Called when all HTTP headers have been received and the body of the response is about to arrive.
This call gives an opportunity to configure the scanner (FlowScanner) or other parser to process the body as it arrives.
Definition at line 50 of file HTTPClient.cpp.
|
virtual |
Called once for each fragment of the body that is received.
len | length of the buffer that contains the body portion received |
data | pointer to the buffer containing the body data |
Definition at line 44 of file HTTPClient.cpp.
|
virtual |
Called once for each fragment of the header portion of the response
len | length of the data byte array containing the header |
data | pointer to the buffer containing the header data |
Definition at line 38 of file HTTPClient.cpp.
|
virtual |
Called after all the body has been received
Definition at line 32 of file HTTPClient.cpp.
|
virtual |
Called immediately after the first line is received and there is a status code, e.g.
200 OK
. The HTTP status code is stored in the statusCode member variable.
Definition at line 28 of file HTTPClient.cpp.
void HTTPClient::request | ( | const String & | hostName, |
const String & | resource, | ||
uint16_t | port = 80 |
||
) |
Starts a new HTTP request.
Any previously ongoing request is aborted.
hostName | Name of the host to connect to, e.g. www.friendev.com |
resource | Resource path, e.g. /index.html |
port | TCP port, 80 by default |
Definition at line 68 of file HTTPClient.cpp.
|
protected |
Internal FlowScanner instance used to detect header/response/status code, etc.
Can be reused to scan the body after onBodyBegin() is called by EtherDune
Definition at line 59 of file HTTPClient.h.
uint16_t HTTPClient::statusCode |
Contains the HTTP status code of the response.
Valid only after onResponseReceived() is called by EtherDune
Definition at line 64 of file HTTPClient.h.