HTTP - reworked status codes
This commit is contained in:
parent
83794c9b64
commit
0e37d600ad
2 changed files with 8 additions and 8 deletions
|
@ -5,7 +5,7 @@ HTTPClient::HTTPClient(TransportLayer* tl, uint16_t port) {
|
||||||
_port = port;
|
_port = port;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t HTTPClient::get(const char* url, String& response) {
|
int16_t HTTPClient::get(const char* url, String& response) {
|
||||||
// get the host address and endpoint
|
// get the host address and endpoint
|
||||||
char* httpPrefix = strstr(url, "http://");
|
char* httpPrefix = strstr(url, "http://");
|
||||||
char* endpoint;
|
char* endpoint;
|
||||||
|
@ -45,7 +45,7 @@ uint16_t HTTPClient::get(const char* url, String& response) {
|
||||||
delete[] endpoint;
|
delete[] endpoint;
|
||||||
|
|
||||||
// create TCP connection
|
// create TCP connection
|
||||||
uint8_t state = _tl->openTransportConnection(host, "TCP", _port);
|
int16_t state = _tl->openTransportConnection(host, "TCP", _port);
|
||||||
delete[] host;
|
delete[] host;
|
||||||
if(state != ERR_NONE) {
|
if(state != ERR_NONE) {
|
||||||
delete[] request;
|
delete[] request;
|
||||||
|
@ -62,7 +62,7 @@ uint16_t HTTPClient::get(const char* url, String& response) {
|
||||||
//delay(1000);
|
//delay(1000);
|
||||||
|
|
||||||
// get the response length
|
// get the response length
|
||||||
uint16_t numBytes = _tl->getNumBytes();
|
size_t numBytes = _tl->getNumBytes();
|
||||||
if(numBytes == 0) {
|
if(numBytes == 0) {
|
||||||
return(ERR_RESPONSE_MALFORMED_AT);
|
return(ERR_RESPONSE_MALFORMED_AT);
|
||||||
}
|
}
|
||||||
|
@ -106,7 +106,7 @@ uint16_t HTTPClient::get(const char* url, String& response) {
|
||||||
return(atoi(statusStr));
|
return(atoi(statusStr));
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t HTTPClient::post(const char* url, const char* content, String& response, const char* contentType) {
|
int16_t HTTPClient::post(const char* url, const char* content, String& response, const char* contentType) {
|
||||||
// get the host address and endpoint
|
// get the host address and endpoint
|
||||||
char* httpPrefix = strstr(url, "http://");
|
char* httpPrefix = strstr(url, "http://");
|
||||||
char* endpoint;
|
char* endpoint;
|
||||||
|
@ -154,7 +154,7 @@ uint16_t HTTPClient::post(const char* url, const char* content, String& response
|
||||||
delete[] endpoint;
|
delete[] endpoint;
|
||||||
|
|
||||||
// create TCP connection
|
// create TCP connection
|
||||||
uint8_t state = _tl->openTransportConnection(host, "TCP", _port);
|
int16_t state = _tl->openTransportConnection(host, "TCP", _port);
|
||||||
delete[] host;
|
delete[] host;
|
||||||
if(state != ERR_NONE) {
|
if(state != ERR_NONE) {
|
||||||
return(state);
|
return(state);
|
||||||
|
@ -168,7 +168,7 @@ uint16_t HTTPClient::post(const char* url, const char* content, String& response
|
||||||
}
|
}
|
||||||
|
|
||||||
// get the response length
|
// get the response length
|
||||||
uint16_t numBytes = _tl->getNumBytes();
|
size_t numBytes = _tl->getNumBytes();
|
||||||
if(numBytes == 0) {
|
if(numBytes == 0) {
|
||||||
return(ERR_RESPONSE_MALFORMED_AT);
|
return(ERR_RESPONSE_MALFORMED_AT);
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,8 +10,8 @@ class HTTPClient {
|
||||||
HTTPClient(TransportLayer* tl, uint16_t port = 80);
|
HTTPClient(TransportLayer* tl, uint16_t port = 80);
|
||||||
|
|
||||||
// basic methods
|
// basic methods
|
||||||
uint16_t get(const char* url, String& response);
|
int16_t get(const char* url, String& response);
|
||||||
uint16_t post(const char* url, const char* content, String& response, const char* contentType = "text/plain");
|
int16_t post(const char* url, const char* content, String& response, const char* contentType = "text/plain");
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TransportLayer* _tl;
|
TransportLayer* _tl;
|
||||||
|
|
Loading…
Add table
Reference in a new issue