int http_post_data(char* host, uint16 port, uint8* file_name)
{
qapi_Status_t ret = -1;
uint8 reconnect_count = 0;
#ifdef QUECTEL_HTTPS_SUPPORT
SSL_INST http_ssl;
#endif
/* Start HTTPc service */
qapi_Net_HTTPc_Start();
memset(&http_session_policy, 0, sizeof(http_session_policy_t));
#ifdef QUECTEL_HTTPS_SUPPORT
if (ssl_ctx_id)
{
/* config object and certificate */
if (0 != http_ssl_config(&http_ssl))
{
SALVATOR_UART_DBG("ERROR: Config ssl object and certificates error");
}
/* create a SSL session */
ssl_obj_hdl = http_ssl.sslCtx;
http_ssl.sslCon = qapi_Net_SSL_Con_New(http_ssl.sslCtx, QAPI_NET_SSL_TLS_E);
if (http_ssl.sslCon == QAPI_NET_SSL_INVALID_HANDLE)
{
SALVATOR_UART_DBG("ERROR: Unable to create SSL context");
return -1;
}
if (QAPI_OK != qapi_Net_SSL_Configure(http_ssl.sslCon, &http_ssl.config))
{
SALVATOR_UART_DBG("ERROR: SSL configure failed");
return -2;
}
http_handle = qapi_Net_HTTPc_New_sess(20000, http_ssl.sslCtx, http_client_cb, NULL, 1024, 1024);
ret = qapi_Net_HTTPc_Configure_SSL(http_handle, &http_ssl.config);
if(ret != QAPI_OK)
{
SALVATOR_UART_DBG("Start HTTPS connection, SSL config ret[%d]", ret);
return -2;
}
}
else
{
http_handle = qapi_Net_HTTPc_New_sess(20000, 0, http_client_cb, NULL, 1024, 1024);
}
#else
http_handle = qapi_Net_HTTPc_New_sess(20000, 0, http_client_cb, NULL, 5 * 1024, 5 * 1024);
#endif /* QUECTEL_HTTPS_SUPPORT */
http_session_policy.session_state = HTTP_SESSION_INIT;
if ( http_handle == NULL)
{
SALVATOR_UART_DBG("qapi_Net_HTTPc_New_sess ERROR");
return -3;
}
// qapi_Net_HTTPc_Pass_Pool_Ptr(http_handle, byte_pool_salvator);
do
{
ret = qapi_Net_HTTPc_Connect(http_handle, host, port);
if (ret != QAPI_OK)
{
reconnect_count++;
SALVATOR_UART_DBG("qapi_Net_HTTPc_Connect ERROR ret:%d, re-connect times:%d",ret,reconnect_count);
if(reconnect_count >= HTPP_MAX_CONNECT_RETRY)
{
return -4;
}
qapi_Timer_Sleep(3, QAPI_TIMER_UNIT_SEC, true);
}
else
{
SALVATOR_UART_DBG("qapi_Net_HTTPc_Connect success :%d", ret);
break;
}
} while (1);
http_session_policy.session_state = HTTP_SESSION_CONN;
qapi_Net_HTTPc_Clear_Header(http_handle);
qapi_Net_HTTPc_Add_Header_Field(http_handle, "Connection", "Keep-Alive");
qapi_Net_HTTPc_Add_Header_Field(http_handle, "Content-Type", "application/x-www-form-urlencoded");
qapi_Net_HTTPc_Add_Header_Field(http_handle, "Content-Length", strlen(Tx_Buffer)); // Not sure if required
http_post_body((char *)Tx_Buffer);
/* get response content */
ret = qapi_Net_HTTPc_Request(http_handle, QAPI_NET_HTTP_CLIENT_POST_E, file_name);
if (ret != QAPI_OK)
{
SALVATOR_UART_DBG("qapi_Net_HTTPc_Request ERROR :%d",ret);
return -5;
}
// http_post_body(Tx_Buffer);
return 0;
}
hi,
Just went through the code, it looks ok. HTTP 500 error should be a server side issue. Can you verify with any other POST API with simple content?
Is there any documentation available for /sos POST REST API?
thanks,
Steve