Go Down

Topic: SIM900A Send HTTP headers (Read 325 times) previous topic - next topic

alexor2k

Hello,

I have trouble to send http authorization header to my server.
In the following example i am trying to send a post request to my server, the content header and the body are received on the server side , but authorization header is not being received.
I tried various examples to make this happen but without any success.

Code: [Select]

void sendGSMData() {
String reading = "{\"wash\":2}";

Serial.println("HTTP get method :");

Serial.print("AT\\r\\n");
GSMModule.println("AT");  /* Check Communication */

Serial.print("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\"\\r\\n");
GSMModule.println("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\"");  /* Connection type GPRS */

Serial.print("AT+SAPBR=3,1,\"APN\",\"uinternet\"\\r\\n");
GSMModule.println("AT+SAPBR=3,1,\"APN\",\"uinternet\"");  /* APN of the provider */

Serial.print("AT+SAPBR=1,1\\r\\n");
GSMModule.println("AT+SAPBR=1,1"); /* Open GPRS context */

Serial.print("AT+SAPBR=2,1\\r\\n");
GSMModule.println("AT+SAPBR=2,1"); /* Query the GPRS context */

Serial.print("AT+HTTPINIT\\r\\n");
GSMModule.println("AT+HTTPINIT"); /* Initialize HTTP service */

Serial.print("AT+HTTPSSL=1\\r\\n");
GSMModule.println("AT+HTTPSSL=1"); /* Initialize SSL service */

Serial.print("AT+CMEE=1\\r\\n");
GSMModule.println("AT+CMEE=1"); /* Initialize Errors service */

Serial.print("AT+HTTPPARA=\"CID\",1\\r\\n");
GSMModule.println("AT+HTTPPARA=\"CID\",1");  /* Set CID parameter for HTTP session */

Serial.print("AT+HTTPPARA=\"URL\",\"299ddbf3397.ngrok.io/data\"\\r\\n");
GSMModule.println("AT+HTTPPARA=\"URL\",\"299ddbf3397.ngrok.io/data\"");  /* Set URL parameter for HTTP session */

    Serial.print("AT+HTTPPARA=\"USERDATA\",\"Authorization: my_auhtorization_key\"\\r\\n");
    GSMModule.println("AT+HTTPPARA=\"USERDATA\",\"Authorization: my_auhtorization_key\"");  /* Set Header parameters for HTTP session */

    Serial.print("AT+HTTPPARA=\"CONTENT\",\"application/json\"");
    GSMModule.println("AT+HTTPPARA=\"CONTENT\",\"application/json\"");  /* Set Content parameters for HTTP session */

    Serial.print("AT+HTTPDATA=" + String(reading.length()) + ",100000");
    GSMModule.println("AT+HTTPDATA=" + String(reading.length()) + ",100000");  /* Set parameters for HTTP session */

    Serial.print(reading);
    GSMModule.println(reading);  /* Set parameters for HTTP session */

Serial.print("AT+HTTPACTION=1\\r\\n");
GSMModule.println("AT+HTTPACTION=1");  /* Start POST session */

Serial.print("AT+HTTPREAD\\r\\n");
GSMModule.println("AT+HTTPREAD");  /* Read data from HTTP server */

Serial.print("AT+HTTPTERM\\r\\n");
GSMModule.println("AT+HTTPTERM");  /* Terminate HTTP service */

Serial.print("AT+SAPBR=0,1\\r\\n");
GSMModule.println("AT+SAPBR=0,1"); /* Close GPRS context */
}


Go Up