82 void HTTPClient::onDNSResolve(uint8_t status, uint16_t identification,
const IPAddress& ip)
84 if (identification == DNSid)
94 ACERROR(
"Could not resolve hostname");
100 void HTTPClient::onConnect()
102 scanner.setPattern(statusCodePattern);
104 bodyBeginPattern.signaled =
false;
106 write(F(
"GET % HTTP/1.1" "\r\n" "Accept:*" "/" "*" "\r\n" "Host:%\r\n\r\n"), &res, &host);
109 void HTTPClient::onReceive(uint16_t len,
const byte* data)
112 if (bodyBeginPattern.signaled)
118 const byte* headerStart = data;
125 if (statusCodePattern.signaled)
140 scanner.setPattern(bodyBeginPattern);
147 if (statusCodePattern.signaled)
153 void HTTPClient::onClose()
void request(const String &hostName, const String &resource, uint16_t port=80)
Starts a new HTTP request.
virtual void onResponseReceived()
Called immediately after the first line is received and there is a status code, e.g.
uint32_t u
access the IP as a uint32_t for convenience
virtual void onBodyBegin()
Called when all HTTP headers have been received and the body of the response is about to arrive...
static DNSClient & DNS()
Obtains access to the DNS service singleton instance.
uint16_t write(uint16_t len, const byte *data)
In the case of TCP, writes the given data buffer to the socket.
static const char bodyBeginPatternString[]
nint16_t remotePort
remote TCP or UDP port
ACROSS_MODULE("HTTPClient")
represents an IP address in memory
FlowScanner scanner
Internal FlowScanner instance used to detect header/response/status code, etc.
void connect()
Initiates a TCP connection to remoteIP and remotePort.
uint16_t statusCode
Contains the HTTP status code of the response.
void zero()
Sets the IP address to zero.
uint16_t resolve(const char *name)
Resolves a host name to an IP address
virtual void onBodyReceived(uint16_t len, const byte *data)
Called once for each fragment of the body that is received.
IPAddress remoteIP
remote IP address to connect to (TCP) or send the next packet to (UDP)
virtual void onHeaderReceived(uint16_t len, const byte *data)
Called once for each fragment of the header portion of the response
virtual void onResponseEnd()
Called after all the body has been received
void close()
Attempts to gracefully close a connection.
static const char statusCodePatternString[]