This is Webservice SDK for mbed. LPCXpresso1769/LPC1768/FRDM-K64F/LPC4088
Dependents: MbedFileServer_1768MiniDK2 RedWireBridge IssueDebug_gcc MiMicRemoteMCU-for-Mbed ... more
HttpClient.h
00001 #pragma once 00002 //////////////////////////////////////////////////////////////////////////////// 00003 // HttpClient.h 00004 //////////////////////////////////////////////////////////////////////////////// 00005 00006 #include "NyLPC_net.h" 00007 #include "IpAddr.h" 00008 00009 namespace MiMic 00010 { 00011 class HttpClient 00012 { 00013 private: 00014 void* _private_tcp_rx_buf; 00015 protected: 00016 NyLPC_TcHttpClient_t _inst; 00017 public: 00018 const static NyLPC_THttpMethodType HTTP_GET=NyLPC_THttpMethodType_GET; 00019 const static NyLPC_THttpMethodType HTTP_POST=NyLPC_THttpMethodType_POST; 00020 const static NyLPC_THttpMethodType HTTP_HEAD=NyLPC_THttpMethodType_HEAD; 00021 const static unsigned int CONTENT_CHUNKED=NyLPC_cHttpHeaderWriter_CONTENT_LENGTH_UNLIMITED; 00022 00023 public: 00024 HttpClient(); 00025 virtual ~HttpClient(); 00026 public: 00027 bool connect(const IpAddr& i_host,unsigned short i_port); 00028 /** 00029 * This function sends a request to server and prevent to accept status code. 00030 * Must call getStatus after successful. 00031 * If request has content body(i_content_length!=0), call writeX function to send request body in before to call getStatus 00032 * @param i_content_length 00033 * size of request body. 00034 * Specify CONTENT_CHUNKED if the size is unknown. 00035 * @return 00036 * true if successful, 00037 * otherwise error. Connection is closed. 00038 * @example 00039 * <code> 00040 * //GET 00041 * </code> 00042 * <code> 00043 * //POST 00044 * 00045 * </code> 00046 */ 00047 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); 00048 /** 00049 * This function returns status code. 00050 * Must call after the sendMethod was successful. 00051 * @return 00052 * Error:0,otherwise HTTP status code. 00053 */ 00054 int getStatus(); 00055 /** 00056 * Close current connection. 00057 */ 00058 void close(); 00059 /** 00060 * Read request body from http stream. 00061 * This function must be call repeatedly until the end of the stream or an error. 00062 * @param i_rx_buf 00063 * A buffer which accepts received data. 00064 * @param i_rx_buf_len 00065 * size of i_rx_buf in byte. 00066 * @param i_read_len 00067 * pointer to variable which accept received data size in byte. 00068 * It is enabled in retrurn true. 00069 * n>0 is datasize. n==0 is end of stream. 00070 * @return 00071 * true if successful,otherwise false 00072 */ 00073 bool read(void* i_rx_buf,int i_rx_buf_len,short &i_read_len); 00074 /** 00075 * Write request body to connected http stream. 00076 * This function must be call repeatedly until the end of the request content or an error. 00077 * Transmission of the request body is completed by to call the AAA in the case of chunked transfer. 00078 * @param i_tx_buf 00079 * @param i_tx_len 00080 * @return 00081 * true if successful. 00082 */ 00083 bool write(const void* i_tx_buf,int i_tx_len); 00084 }; 00085 }
Generated on Tue Jul 12 2022 15:46:14 by 1.7.2