Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
HttpClient.h
00001 #ifndef __HTTP_CLIENT_H__ 00002 #define __HTTP_CLIENT_H__ 00003 00004 #include "mbed.h" 00005 #include <string> 00006 #include <map> 00007 #include "TCPSocketConnection.h" 00008 00009 enum content_type{ 00010 CONTENT_TYPE_TEXT, 00011 CONTENT_TYPE_APPLICATION, 00012 CONTENT_TYPE_IMAGE, 00013 CONTENT_TYPE_MESSAGE 00014 }; 00015 00016 00017 typedef struct { 00018 int http_response; 00019 std::string http_response_text; 00020 std::map<std::string, std::string> http_info; 00021 } HeaderInfo; 00022 00023 class HttpClient 00024 { 00025 public: 00026 HttpClient(const char * hostname); 00027 int get(const char * url, char * buffer, size_t buf_len, HeaderInfo & hinfo, int timeout = 5000); 00028 00029 private: 00030 std::string build_http_headers(std::string type, std::string path); 00031 int parse_url(const char* url, 00032 char* scheme, 00033 size_t scheme_len, 00034 char* host, 00035 size_t host_len, 00036 uint16_t* port, 00037 char* path, size_t max_path); 00038 00039 int parse_headers(std::string header_line, HeaderInfo & hinfo, int line); 00040 00041 int read_data(HeaderInfo & hinfo, char * buffer, size_t buf_len); 00042 00043 int send(char* buf, size_t len); 00044 // Receive untill a char term is received 00045 int recv_until(char * buf, size_t len, char term); 00046 00047 std::string _hostname; // The name of this local host 00048 int _timeout; 00049 TCPSocketConnection m_sock; 00050 int _httpResponse; 00051 }; 00052 00053 #endif 00054
Generated on Tue Jul 12 2022 18:55:01 by
1.7.2