Closed vt-vaio closed 9 months ago
I've sorted the issue. My problem was in the the 4th parameter (dataSize). The sizeof always returned 4. By changing the code in the following way all works now.
std::string smsg = "{'id':'240ac4c6f33c','fw_version':'3.0'}";
const uint8_t *msg = reinterpret_cast<const uint8_t*>(smsg.c_str());
bool sent = m_modem->httpSend(1, "/my-endpoint", (uint8_t *) msg, smsg.length(), WALTER_MODEM_HTTP_SEND_CMD_POST, WALTER_MODEM_HTTP_POST_PARAM_JSON);
Solved, please see my previous comment for solution. Thank you.
I need to send a post request via HTTP with JSON in the request body. I was trying to use httpSend() but always getting a 400 response from the backend. For me it looks like that JSON string is never transmitted as part of the request. I can reproduce the same 400 error with Postman when removing the JSON string from the body.
Below is a code snipped from my tests (the backend and API endpoints are replaced with placeholders).
Below is some debug output
TX: AT+SQNHTTPCFG=1,"my-backend",80,0,"","" RX: OK TX: AT+SQNHTTPSND=1,0,"/my-endpoint",4,"4" RX: > RX: OK RX: +SQNHTTPRING: 1,400,"text/html; charset=UTF-8",0 TX: AT+SQNHTTPRCV=1 RX: +CME ERROR: 587 TX: AT+SQNHTTPRCV=1 RX: +CME ERROR: 587 TX: AT+SQNHTTPRCV=1 RX: +CME ERROR: 587