-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHttpClient.h
66 lines (51 loc) · 1.79 KB
/
HttpClient.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#ifndef HttpClient_h
#define HttpClient_h
#include "Arduino.h"
#include "Client.h"
class HttpClient{
public:
HttpClient(Client& cl);
//Les status que peut prendre la connection HTTP
typedef enum {
HTTP_STATUS_IDLE, //Aucune requete http en cours
HTTP_STATUS_RESP_WAIT, //En attente de la réponse
HTTP_STATUS_RESP_BEGIN, //Au début de la réponse (avant HTTP/1.1)
HTTP_STATUS_RESP_HEADER, //Au début d'une ligne d'en-tête
HTTP_STATUS_RESP_BODY, //Corps de la réponse
HTTP_STATUS_ERROR, //Une erreur est survenue
HTTP_STATUS_EOF //La fin de fichier a été atteinte
} HttpState;
//Les codes retours possibles (négatifs pour les différencier du nombre de caractères que peuvent renvoyer certaines fonctions)
#define HTTP_ERROR -2
#define HTTP_ERROR_BUFFER_OVERFLOW -3
#define HTTP_ERROR_TIMEOUT -4
#define HTTP_ERROR_CONNECTION_FAILED -5
#define HTTP_ERROR_STATUS -6
#define HTTP_DEFAULT_TIMEOUT 3000; //Timeout http par défaut
HttpState status; //Status courant de la connection
void reset();
void close();
void setTimeout(int millis);
void setDebug(boolean debug);
//int sendGet(char* server, int port, char* path);
int sendGet(char* server, int port, char* path, char* params);
int readResponseCode();
int readLineToChar(char sep, char* key,int maxlen);
int skipHeaders();
int moveToEOL();
int available();
int waitForResponse();
int httpRead();
protected:
Client* client; //Interface Client (ethernet, GSM, Wifi ...)
int print(char* str);
int println(char* str);
boolean connect(char* serv, int port);
int error(int err);
private:
int startMillis; //timestamp de démarrage de la requete en cours (sert pour le timeout)
int timeout; //configuration de timeout en cours
boolean debug;
boolean lastConnected;
};
#endif