liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 1 | #include <stdio.h> |
| 2 | #include <string.h> |
| 3 | #include <sys/types.h> |
| 4 | #include <sys/stat.h> |
| 5 | #include <fcntl.h> |
| 6 | #include <errno.h> |
| 7 | |
| 8 | #define LOG_TAG "mbtk_http" |
| 9 | #include "mbtk_type.h" |
| 10 | #include "mbtk_http.h" |
| 11 | #include "mbtk_log.h" |
| 12 | |
| 13 | |
| 14 | static void http_data_cb_func( |
| 15 | int session_id, mbtk_http_data_type_enum type, |
| 16 | void *data,int data_len) |
| 17 | { |
| 18 | if(type == MBTK_HTTP_DATA_HEADER) { |
| 19 | printf("Header(%d):%s\n",data_len,(char*)data); |
| 20 | } else if(type == MBTK_HTTP_DATA_CONTENT) { |
| 21 | printf("Data(%d):%s\n",data_len,(char*)data); |
| 22 | } else { |
| 23 | LOGI(">>>>>Complete<<<<<\n"); |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | int main(int argc, char *argv[]) |
| 28 | { |
| 29 | if(argc != 2) { |
| 30 | LOGE("ARG error."); |
| 31 | return -1; |
| 32 | } |
| 33 | |
| 34 | LOGI("MBTK HTTP Version 1.1"); |
| 35 | |
| 36 | int http_handle = mbtk_http_handle_get(TRUE, http_data_cb_func); |
| 37 | if(http_handle < 0) |
| 38 | { |
| 39 | LOGE("mbtk_http_handle_get() fail."); |
| 40 | return -1; |
| 41 | } |
| 42 | |
| 43 | int http_session = mbtk_http_session_create(http_handle,HTTP_OPTION_GET,HTTP_VERSION_1_1); |
| 44 | if(http_handle < 0) |
| 45 | { |
| 46 | LOGE("mbtk_http_session_create() fail."); |
| 47 | return -1; |
| 48 | } |
| 49 | |
| 50 | if(mbtk_http_session_url_set(http_handle, http_session, argv[1])) { |
| 51 | LOGE("mbtk_http_session_url_set() fail.\n"); |
| 52 | return -1; |
| 53 | } |
| 54 | |
| 55 | const mbtk_http_session_t* session = mbtk_http_session_get(http_handle, http_session); |
| 56 | LOGI("HTTP:%d,%s,%d,%s\n",session->option,session->host,session->port,session->uri); |
| 57 | |
| 58 | |
| 59 | if(mbtk_http_session_start(http_handle, http_session)) { |
| 60 | LOGE("mbtk_http_session_start() fail.\n"); |
| 61 | return -1; |
| 62 | } |
| 63 | |
| 64 | |
| 65 | if(mbtk_http_handle_free(http_handle)) |
| 66 | { |
| 67 | LOGE("mbtk_http_handle_free() fail."); |
| 68 | return -1; |
| 69 | } |
| 70 | |
| 71 | LOGI("MBTK_HTTP exit."); |
| 72 | return 0; |
| 73 | |
| 74 | } |