This is Webservice SDK for mbed. LPCXpresso1769/LPC1768/FRDM-K64F/LPC4088
Fork of libMiMic by
mbed/HttpClient.h@115:fa79286d8ea4, 2017-02-24 (annotated)
- Committer:
- furutani
- Date:
- Fri Feb 24 04:43:41 2017 +0000
- Revision:
- 115:fa79286d8ea4
- Parent:
- 62:8be8c5924c3e
Delete missing include line.; Add parameter "timeout" to TCPSocket::connect(), precv().; Fix to send ARP request to default gateway when connecting to IP address of different segment.;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nyatla | 58:03b89038b21a | 1 | #pragma once |
nyatla | 58:03b89038b21a | 2 | //////////////////////////////////////////////////////////////////////////////// |
nyatla | 58:03b89038b21a | 3 | // HttpClient.h |
nyatla | 58:03b89038b21a | 4 | //////////////////////////////////////////////////////////////////////////////// |
nyatla | 58:03b89038b21a | 5 | |
nyatla | 58:03b89038b21a | 6 | #include "NyLPC_net.h" |
nyatla | 58:03b89038b21a | 7 | #include "IpAddr.h" |
nyatla | 58:03b89038b21a | 8 | |
nyatla | 58:03b89038b21a | 9 | namespace MiMic |
nyatla | 58:03b89038b21a | 10 | { |
nyatla | 58:03b89038b21a | 11 | class HttpClient |
nyatla | 58:03b89038b21a | 12 | { |
nyatla | 58:03b89038b21a | 13 | private: |
nyatla | 58:03b89038b21a | 14 | void* _private_tcp_rx_buf; |
nyatla | 58:03b89038b21a | 15 | protected: |
nyatla | 58:03b89038b21a | 16 | NyLPC_TcHttpClient_t _inst; |
nyatla | 58:03b89038b21a | 17 | public: |
nyatla | 58:03b89038b21a | 18 | const static NyLPC_THttpMethodType HTTP_GET=NyLPC_THttpMethodType_GET; |
nyatla | 58:03b89038b21a | 19 | const static NyLPC_THttpMethodType HTTP_POST=NyLPC_THttpMethodType_POST; |
nyatla | 58:03b89038b21a | 20 | const static NyLPC_THttpMethodType HTTP_HEAD=NyLPC_THttpMethodType_HEAD; |
nyatla | 58:03b89038b21a | 21 | const static unsigned int CONTENT_CHUNKED=NyLPC_cHttpHeaderWriter_CONTENT_LENGTH_UNLIMITED; |
nyatla | 58:03b89038b21a | 22 | |
nyatla | 58:03b89038b21a | 23 | public: |
nyatla | 58:03b89038b21a | 24 | HttpClient(); |
nyatla | 58:03b89038b21a | 25 | virtual ~HttpClient(); |
nyatla | 58:03b89038b21a | 26 | public: |
nyatla | 58:03b89038b21a | 27 | bool connect(const IpAddr& i_host,unsigned short i_port); |
nyatla | 58:03b89038b21a | 28 | /** |
nyatla | 58:03b89038b21a | 29 | * This function sends a request to server and prevent to accept status code. |
nyatla | 58:03b89038b21a | 30 | * Must call getStatus after successful. |
nyatla | 58:03b89038b21a | 31 | * If request has content body(i_content_length!=0), call writeX function to send request body in before to call getStatus |
nyatla | 58:03b89038b21a | 32 | * @param i_content_length |
nyatla | 58:03b89038b21a | 33 | * size of request body. |
nyatla | 58:03b89038b21a | 34 | * Specify CONTENT_CHUNKED if the size is unknown. |
nyatla | 58:03b89038b21a | 35 | * @return |
nyatla | 58:03b89038b21a | 36 | * true if successful, |
nyatla | 58:03b89038b21a | 37 | * otherwise error. Connection is closed. |
nyatla | 58:03b89038b21a | 38 | * @example |
nyatla | 58:03b89038b21a | 39 | * <code> |
nyatla | 58:03b89038b21a | 40 | * //GET |
nyatla | 58:03b89038b21a | 41 | * </code> |
nyatla | 58:03b89038b21a | 42 | * <code> |
nyatla | 58:03b89038b21a | 43 | * //POST |
nyatla | 58:03b89038b21a | 44 | * |
nyatla | 58:03b89038b21a | 45 | * </code> |
nyatla | 58:03b89038b21a | 46 | */ |
nyatla | 58:03b89038b21a | 47 | bool sendMethod(NyLPC_THttpMethodType i_method,const char* i_path,int i_content_length=0,const char* i_mimetype=NULL,const char* i_additional_header=NULL); |
nyatla | 58:03b89038b21a | 48 | /** |
nyatla | 58:03b89038b21a | 49 | * This function returns status code. |
nyatla | 58:03b89038b21a | 50 | * Must call after the sendMethod was successful. |
nyatla | 58:03b89038b21a | 51 | * @return |
nyatla | 58:03b89038b21a | 52 | * Error:0,otherwise HTTP status code. |
nyatla | 58:03b89038b21a | 53 | */ |
nyatla | 58:03b89038b21a | 54 | int getStatus(); |
nyatla | 58:03b89038b21a | 55 | /** |
nyatla | 58:03b89038b21a | 56 | * Close current connection. |
nyatla | 58:03b89038b21a | 57 | */ |
nyatla | 58:03b89038b21a | 58 | void close(); |
nyatla | 58:03b89038b21a | 59 | /** |
nyatla | 58:03b89038b21a | 60 | * Read request body from http stream. |
nyatla | 58:03b89038b21a | 61 | * This function must be call repeatedly until the end of the stream or an error. |
nyatla | 58:03b89038b21a | 62 | * @param i_rx_buf |
nyatla | 58:03b89038b21a | 63 | * A buffer which accepts received data. |
nyatla | 58:03b89038b21a | 64 | * @param i_rx_buf_len |
nyatla | 58:03b89038b21a | 65 | * size of i_rx_buf in byte. |
nyatla | 58:03b89038b21a | 66 | * @param i_read_len |
nyatla | 58:03b89038b21a | 67 | * pointer to variable which accept received data size in byte. |
nyatla | 58:03b89038b21a | 68 | * It is enabled in retrurn true. |
nyatla | 58:03b89038b21a | 69 | * n>0 is datasize. n==0 is end of stream. |
nyatla | 58:03b89038b21a | 70 | * @return |
nyatla | 58:03b89038b21a | 71 | * true if successful,otherwise false |
nyatla | 58:03b89038b21a | 72 | */ |
nyatla | 62:8be8c5924c3e | 73 | bool read(void* i_rx_buf,int i_rx_buf_len,short &i_read_len); |
nyatla | 58:03b89038b21a | 74 | /** |
nyatla | 58:03b89038b21a | 75 | * Write request body to connected http stream. |
nyatla | 58:03b89038b21a | 76 | * This function must be call repeatedly until the end of the request content or an error. |
nyatla | 58:03b89038b21a | 77 | * Transmission of the request body is completed by to call the AAA in the case of chunked transfer. |
nyatla | 58:03b89038b21a | 78 | * @param i_tx_buf |
nyatla | 58:03b89038b21a | 79 | * @param i_tx_len |
nyatla | 58:03b89038b21a | 80 | * @return |
nyatla | 58:03b89038b21a | 81 | * true if successful. |
nyatla | 58:03b89038b21a | 82 | */ |
nyatla | 58:03b89038b21a | 83 | bool write(const void* i_tx_buf,int i_tx_len); |
nyatla | 58:03b89038b21a | 84 | }; |
nyatla | 58:03b89038b21a | 85 | } |