Tool/software: TI-RTOS
I am working on my senior design project. I need to send get and post requests to my raspberry pi server. I can do both successfully via Postman. I can also successfully do a get by following the httpget example. However, when I try to do a post I am getting error 400. I have compared a successful payload from Postman vs an error payload via the simplelink, used wireshark for this purpose. I notice that when sending it via wireshark I do not even see the body being sent.
#define HOSTNAME "http://192.168.1.10:8080" #define POST_URI_USER_CREATE "/restserver/webapi/user/create/" #define USER_AGENT_POST "application/json" const char body[] = "{\"user_name\":\"GeoChirino\"}"; // Wait for semaphore, this indicates we are connected and the interface is setup: sem_wait(&ipEventSyncObj); bool moreDataFlag = false; char data[HTTP_MIN_RECV]; int16_t ret = 0; int16_t len = 0; HTTPClient_Handle httpClientHandle; int16_t statusCode; httpClientHandle = HTTPClient_create(&statusCode,0); if(statusCode < 0){printError("httpTask: creation of http client handle failed", statusCode);} ret = HTTPClient_setHeader(httpClientHandle, HTTPClient_HFIELD_REQ_CONTENT_TYPE, USER_AGENT_POST,strlen(USER_AGENT_POST), HTTPClient_HFIELD_PERSISTENT); if(ret < 0){printError("httpTask: setting request header failed", ret);} ret = HTTPClient_connect(httpClientHandle,HOSTNAME,0,0); if(ret < 0){printError("httpTask: connect failed", ret);} ret = HTTPClient_sendRequest(httpClientHandle, HTTP_METHOD_POST, POST_URI_USER_CREATE, body,strlen(body), 0); if(ret < 0){printError("httpTask: send failed", ret);}
From wireshark I also see that the content type is as "application/json�" ()note the special character. I do not see this on a working post from Postman.