#define HTTP_PORT_NUM 80 #define HTTPS_PORT_NUM 443 #define TEST_SETOPTIONS_CERTIFICATE (const unsigned char*)"blah!blah!blah!" #define host_name (const char*)"i.imgur.com" #define REQUEST_RELATIVE_PATH "/z4d4kWk.jpg" typedef struct BUFFER_TAG* BUFFER_HANDLE; typedef struct HTTP_HEADERS_HANDLE_DATA_TAG* HTTP_HEADERS_HANDLE; typedef struct HTTP_HANDLE_DATA_TAG* HTTP_CLIENT_HANDLE; static BUFFER_HANDLE TestBufferHandle; static HTTP_HEADERS_HANDLE requestHttpHeaders; static HTTP_HEADERS_HANDLE responseHttpHeaders; static void createHttpObjects(HTTP_HEADERS_HANDLE* requestHttpHeaders, HTTP_HEADERS_HANDLE* responseHttpHeaders) { /*assumed to never fail*/ *requestHttpHeaders = HTTPHeaders_Alloc(); *responseHttpHeaders = HTTPHeaders_Alloc(); if ( (*requestHttpHeaders == NULL) || (*responseHttpHeaders == NULL) ) { //ASSERT_FAIL("unable to build test prerequisites"); } } static void test_http_get(void) { int port_num = HTTP_PORT_NUM; HTTP_SAMPLE_INFO sample_info; sample_info.stop_running = 0; unsigned int statusCode = 0; unsigned int minimumPollingTime = 9; int result; createHttpObjects(&requestHttpHeaders, &responseHttpHeaders); result = HTTPAPI_Init(); Display_printf(display, 0, 0, "HTTPAPI_Init %d",result ); HTTP_CLIENT_HANDLE http_handle = HTTPAPI_CreateConnection(host_name); if (http_handle == NULL) { Display_printf(display, 0, 0, "HTTPAPI_CreateConnection Failed"); } else { Display_printf(display, 0, 0, "HTTPAPI_CreateConnection Success"); //HTTPAPI_SetOption(http_handle, "TrustedCerts", TEST_SETOPTIONS_CERTIFICATE); HTTPAPI_SetOption(http_handle, "MinimumPollingTime", &minimumPollingTime); int retval = HTTPAPI_ExecuteRequest(http_handle, HTTPAPI_REQUEST_GET, REQUEST_RELATIVE_PATH, requestHttpHeaders, NULL, 0, &statusCode, responseHttpHeaders, TestBufferHandle ); if(retval != HTTPAPI_OK) { Display_printf(display, 0, 0, "HTTPAPI_ExecuteRequest Failed.%d", retval); //Error >> retval = HTTPAPI_OPEN_REQUEST_FAILED } else { Display_printf(display, 0, 0, "HTTPAPI_ExecuteRequest Success."); } HTTPAPI_CloseConnection(http_handle); HTTPAPI_Deinit(); } } void simplesample_http_run(void) { if (platform_init() != 0) { Display_printf(display, 0, 0, "Failed to initialize the platform."); } else { if (serializer_init(NULL) != SERIALIZER_OK) { Display_printf(display, 0, 0, "Failed on serializer_init"); } else { Display_printf(display, 0, 0, "Sending HTTP GET"); test_http_get(); serializer_deinit(); } platform_deinit(); } }