Other Parts Discussed in Thread: CC3235SF
mqtt_client example https://dev.ti.com/tirex/explore/node?node=A__AD9cEx5hEqURlOA0mTXzqg__com.ti.SIMPLELINK_CC32XX_SDK__fc2e6sr__LATEST&placeholder=true
HTTP server POST request respone empty content
simple test setup, handle the request and response "OK"
int HttpCB_test(httpHandle_t hRequest, uint8_t *pPayload, uint16_t payloadLen)
{
LOG_DEBUG("HttpCB_test");
return HTTPSRV_IF_respond(hRequest, 0, "OK", 2);
}
//register
if(rc == 0)
rc = HTTPSRV_IF_registerCallback(SL_NETAPP_REQUEST_HTTP_GET, "/test", HttpCB_test);
if(rc == 0)
rc = HTTPSRV_IF_registerCallback(SL_NETAPP_REQUEST_HTTP_POST, "/test", HttpCB_test);
make reuqest with curl
➜ mqtt_client_CC3235SF_LAUNCHXL_tirtos7_ticlang curl -v -k https://10.0.17.139/test * Trying 10.0.17.139:443... * Connected to 10.0.17.139 (10.0.17.139) port 443 * ALPN: curl offers h2,http/1.1 * (304) (OUT), TLS handshake, Client hello (1): * (304) (IN), TLS handshake, Server hello (2): * TLSv1.2 (IN), TLS handshake, Certificate (11): * TLSv1.2 (IN), TLS handshake, Server finished (14): * TLSv1.2 (OUT), TLS handshake, Client key exchange (16): * TLSv1.2 (OUT), TLS change cipher, Change cipher spec (1): * TLSv1.2 (OUT), TLS handshake, Finished (20): * TLSv1.2 (IN), TLS change cipher, Change cipher spec (1): * TLSv1.2 (IN), TLS handshake, Finished (20): * SSL connection using TLSv1.2 / AES256-SHA * ALPN: server did not agree on a protocol. Uses default. * Server certificate: * subject: C=IL; ST=Sharon; L=Raanana; O=Texas Instruments Inc.; OU=RND; CN=dummy-root-ca-cert * start date: Sep 11 13:18:10 2016 GMT * expire date: Sep 9 13:18:10 2026 GMT * issuer: C=IL; ST=Sharon; L=Raanana; O=Texas Instruments Inc.; OU=RND; CN=dummy-root-ca-cert * SSL certificate verify result: self signed certificate (18), continuing anyway. * using HTTP/1.x > GET /test HTTP/1.1 > Host: 10.0.17.139 > User-Agent: curl/8.4.0 > Accept: */* > * HTTP 1.0, assume close after body < HTTP/1.0 200 OK < Server: WebServer V1.0 < Content-Type: text/html < Content-Length: 2 < * Closing connection * TLSv1.2 (OUT), TLS alert, close notify (256): OK% ➜ mqtt_client_CC3235SF_LAUNCHXL_tirtos7_ticlang curl -v -k -X POST https://10.0.17.139/test * Trying 10.0.17.139:443... * Connected to 10.0.17.139 (10.0.17.139) port 443 * ALPN: curl offers h2,http/1.1 * (304) (OUT), TLS handshake, Client hello (1): * (304) (IN), TLS handshake, Server hello (2): * TLSv1.2 (IN), TLS handshake, Certificate (11): * TLSv1.2 (IN), TLS handshake, Server finished (14): * TLSv1.2 (OUT), TLS handshake, Client key exchange (16): * TLSv1.2 (OUT), TLS change cipher, Change cipher spec (1): * TLSv1.2 (OUT), TLS handshake, Finished (20): * TLSv1.2 (IN), TLS change cipher, Change cipher spec (1): * TLSv1.2 (IN), TLS handshake, Finished (20): * SSL connection using TLSv1.2 / AES256-SHA * ALPN: server did not agree on a protocol. Uses default. * Server certificate: * subject: C=IL; ST=Sharon; L=Raanana; O=Texas Instruments Inc.; OU=RND; CN=dummy-root-ca-cert * start date: Sep 11 13:18:10 2016 GMT * expire date: Sep 9 13:18:10 2026 GMT * issuer: C=IL; ST=Sharon; L=Raanana; O=Texas Instruments Inc.; OU=RND; CN=dummy-root-ca-cert * SSL certificate verify result: self signed certificate (18), continuing anyway. * using HTTP/1.x > POST /test HTTP/1.1 > Host: 10.0.17.139 > User-Agent: curl/8.4.0 > Accept: */* > * HTTP 1.0, assume close after body < HTTP/1.0 500 Internal Server Error < Server: WebServer V1.0 < * Closing connection * TLSv1.2 (OUT), TLS alert, close notify (256): ➜ mqtt_client_CC3235SF_LAUNCHXL_tirtos7_ticlang
uart output
.[0;33m[HTTPSRV::DEBUG] NetApp Request Received - AppId = 1, Type = 1, Handle = 401 .[0;33m[HTTPSRV::DEBUG] handling netapp request .[0;33m[HTTPSRV::DEBUG] HTTPSRVThread:: (type=1) .[0;33m[HTTPSRV::DEBUG] HTTPGetHandler:: (uri=/test..) .[0;33m[HTTPSRV::DEBUG] searchMetadata:: Can't find type=3 .[0;33m[HTTPSRV::DEBUG] wifi_http_respond:: Metadata len = 24 (status=0) .[0;33m[HTTPSRV::DEBUG] wifi_http_respond:: Data len = 2 (status=0) .[0;33m[HTTPSRV::DEBUG] NetApp Request Received - AppId = 1, Type = 2, Handle = 418 .[0;31m[HTTPSRV::ERROR] unsupported netapp request! .[0;31m[WIFI::ERROR] [NETAPP EVENT] Unhandled event [0x10187b]
GET request respone OK as expected and POST shows "unsupported netapp request!"
then look into httpsrv_if.c
const httpRequestHandler_f httpCallbacks[4] =
{
(httpRequestHandler_f)HTTPGetHandler, // GET
NULL, // DELETE
(httpRequestHandler_f)HTTPPostHandler, // POST
NULL, // PUT
};
the POST handle order is not correct since the index is request type - 1
#define SL_NETAPP_REQUEST_HTTP_GET 1 #define SL_NETAPP_REQUEST_HTTP_POST 2 #define SL_NETAPP_REQUEST_HTTP_PUT 3 #define SL_NETAPP_REQUEST_HTTP_DELETE 4
so I adjust the callback to
const httpRequestHandler_f httpCallbacks[4] =
{
(httpRequestHandler_f)HTTPGetHandler, // GET
(httpRequestHandler_f)HTTPPostHandler, // POST
NULL, // DELETE
NULL, // PUT
};
now the post Handler can be called and back to orginal problem and make request with curl again, the GET request still work as expected and the POST request response nothing
➜ mqtt_client_CC3235SF_LAUNCHXL_tirtos7_ticlang curl -v -k https://10.0.17.139/test * Trying 10.0.17.139:443... * Connected to 10.0.17.139 (10.0.17.139) port 443 * ALPN: curl offers h2,http/1.1 * (304) (OUT), TLS handshake, Client hello (1): * (304) (IN), TLS handshake, Server hello (2): * TLSv1.2 (IN), TLS handshake, Certificate (11): * TLSv1.2 (IN), TLS handshake, Server finished (14): * TLSv1.2 (OUT), TLS handshake, Client key exchange (16): * TLSv1.2 (OUT), TLS change cipher, Change cipher spec (1): * TLSv1.2 (OUT), TLS handshake, Finished (20): * TLSv1.2 (IN), TLS change cipher, Change cipher spec (1): * TLSv1.2 (IN), TLS handshake, Finished (20): * SSL connection using TLSv1.2 / AES256-SHA * ALPN: server did not agree on a protocol. Uses default. * Server certificate: * subject: C=IL; ST=Sharon; L=Raanana; O=Texas Instruments Inc.; OU=RND; CN=dummy-root-ca-cert * start date: Sep 11 13:18:10 2016 GMT * expire date: Sep 9 13:18:10 2026 GMT * issuer: C=IL; ST=Sharon; L=Raanana; O=Texas Instruments Inc.; OU=RND; CN=dummy-root-ca-cert * SSL certificate verify result: self signed certificate (18), continuing anyway. * using HTTP/1.x > GET /test HTTP/1.1 > Host: 10.0.17.139 > User-Agent: curl/8.4.0 > Accept: */* > * HTTP 1.0, assume close after body < HTTP/1.0 200 OK < Server: WebServer V1.0 < Content-Type: text/html < Content-Length: 2 < * Closing connection * TLSv1.2 (OUT), TLS alert, close notify (256): OK% ➜ mqtt_client_CC3235SF_LAUNCHXL_tirtos7_ticlang curl -v -k -X POST https://10.0.17.139/test * Trying 10.0.17.139:443... * Connected to 10.0.17.139 (10.0.17.139) port 443 * ALPN: curl offers h2,http/1.1 * (304) (OUT), TLS handshake, Client hello (1): * (304) (IN), TLS handshake, Server hello (2): * TLSv1.2 (IN), TLS handshake, Certificate (11): * TLSv1.2 (IN), TLS handshake, Server finished (14): * TLSv1.2 (OUT), TLS handshake, Client key exchange (16): * TLSv1.2 (OUT), TLS change cipher, Change cipher spec (1): * TLSv1.2 (OUT), TLS handshake, Finished (20): * TLSv1.2 (IN), TLS change cipher, Change cipher spec (1): * TLSv1.2 (IN), TLS handshake, Finished (20): * SSL connection using TLSv1.2 / AES256-SHA * ALPN: server did not agree on a protocol. Uses default. * Server certificate: * subject: C=IL; ST=Sharon; L=Raanana; O=Texas Instruments Inc.; OU=RND; CN=dummy-root-ca-cert * start date: Sep 11 13:18:10 2016 GMT * expire date: Sep 9 13:18:10 2026 GMT * issuer: C=IL; ST=Sharon; L=Raanana; O=Texas Instruments Inc.; OU=RND; CN=dummy-root-ca-cert * SSL certificate verify result: self signed certificate (18), continuing anyway. * using HTTP/1.x > POST /test HTTP/1.1 > Host: 10.0.17.139 > User-Agent: curl/8.4.0 > Accept: */* > * HTTP 1.0, assume close after body < HTTP/1.0 200 OK < Server: WebServer V1.0 < Content-Type: text/html < Content-Length: 2 < * transfer closed with 2 bytes remaining to read * Closing connection * TLSv1.2 (OUT), TLS alert, close notify (256): curl: (18) transfer closed with 2 bytes remaining to read ➜ mqtt_client_CC3235SF_LAUNCHXL_tirtos7_ticlang
uart output
.[0;33m[HTTPSRV::DEBUG] NetApp Request Received - AppId = 1, Type = 1, Handle = 257 .[0;33m[HTTPSRV::DEBUG] handling netapp request .[0;33m[HTTPSRV::DEBUG] HTTPSRVThread:: (type=1) .[0;33m[HTTPSRV::DEBUG] HTTPGetHandler:: (uri=/test..) .[0;33m[HTTPSRV::DEBUG] searchMetadata:: Can't find type=3 .[0;33m[HTTPSRV::DEBUG] wifi_http_respond:: Metadata len = 24 (status=0) .[0;33m[HTTPSRV::DEBUG] wifi_http_respond:: Data len = 2 (status=0) .[0;33m[HTTPSRV::DEBUG] NetApp Request Received - AppId = 1, Type = 2, Handle = 274 .[0;33m[HTTPSRV::DEBUG] handling netapp request .[0;33m[HTTPSRV::DEBUG] HTTPSRVThread:: (type=2) .[0;33m[HTTPSRV::DEBUG] searchMetadata:: Can't find type=3 .[0;33m[HTTPSRV::DEBUG] wifi_http_respond:: Metadata len = 24 (status=0) .[0;33m[HTTPSRV::DEBUG] wifi_http_respond:: Data len = 2 (status=65530)