I am trying to test out HTTP request methods from ssl_client2 to a test server. The GET and DELETE requests work fine, however the PUT and POST requests only send the headers to the server and no body. The server receives the PUT/POST response but returns an error of a 400 Bad Request, due to the PUT/POST body being empty.
I am modifying the GET_REQUEST with the appropriate headers and JSON-formatted parameters (just for testing purposes). Reading the documentation for mbedtls_ssl_write it says the function might do partial writes in some cases if the return value is non-negative and less than length, but when checking the values the return value is equal to the length so there should be no issues there.
I am able to use curl with the same headers and body to successfully make PUT/POST requests, so the server doesn’t like some format that is being passed from the client. I tried passing just plain text and other text just to see if a body is passed at all to the server, and it is empty every time.
curl -H “Content-Type: application/json” -k --key key.pem --cacert rootcacert.pem --cert cert.pem https://10.0.2.15:8443/sep2/edev/4/sub --ciphers ECDHE-ECDSA-AES128-CCM8 -X POST -v -d ‘{“Subscription”:{“encoding”:“0”,“level”:“+S0”,“limit”:“7”,“subscribedResource”:“/sep2/edev/4”,“notificationURI”:“https://10.0.2.15:3443”}}’ //the different ports are intended
Is there something simple I am missing or doing incorrectly? I noticed there is an HTTP-client for Mbed OS but I’m assuming that isn’t needed here since we’re able to write the request in the first place?
Is it intentional that you have an additional '' character at the end of your GET_REQUEST definition?
If you showed your GET_REQUEST as it is in your code, and same lines, then your GET_REQUEST is:
> Write to server:len is 201
tail_len: 4
len+=tail_len: 205
written: 0
ret val of mbedtls_ssl_write: 205
written+=ret: 205
205 bytes written in 1 fragments
POST / HTTP/1.0
Content-type: application/json
{"Subscription":{"encoding":"0","level":"+S0","limit":9,"subscribedResource":"/sep2/edev/4","notificationURI":"https://10.0.2.15:3443"}}
< Read from server: 336 bytes read
HTTP/1.1 400 Bad Request
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET,PUT,POST,DELETE, OPTIONS
Access-Control-Allow-Headers: Content-Type, Authorization
Access-Control-Expose-Headers: Location
Content-Type: text/html; charset=utf-8
Content-Length: 22
Date: Tue, 21 May 2019 17:07:02 GMT
Connection: close
. Closing the connection... done
Based on the printout it seems the quotations are correct. As you can see I’ve added a couple print statements in step 6 - Write the GET request - of the client. We can see tail_len and the value is not 0. Also, I’m not sure I’m seeing the reason why you included the notificationURI IP address enclosed in both brackets and parentheses?
Since the error is an HTTP code, i don’t think htis is related to the TLS data.
However, I compared the working command from your curl command, and the failed command in TLS, and saw one difference:
curl:
“limit”:“7”
Mbed TLS:
"limit":9
I don’t think that the difference in the value matters, however, as you can see, in the working curl command you are sending the value as a string, and in the Mbed TLS command, you are sending the value as an integer. Could this be the issue?