I've been struggling to make a successful POST request to a server a coworker of mine maintains.
I am using a Mega2560, connected to an xbee 3g modem (XBC-M5-UT-001) via the Serial1 port.
I have been able to successfully configure the modem using AT commands via the arduino, as well as send/receive SMS messages.
Also, using XCTU (the configuration/terminal software provided by digi) I am able to configure the modem, send/receive SMS, as well as send a POST request and receive the response.
However, when I try to perform a POST request via the arduino nothing happens. I'm fairly certain I am sending the request correctly (I've tried several different methods), but I can't seem to get a response.
I am sending the request like this:
Serial1.println("POST /loginAjax/ HTTP/1.1");
Serial1.println("Host: dev-aquhivedata.herokuapp.com");
Serial1.println("Content-Type: application/x-www-form-urlencoded");
Serial1.println("Content-Length: 28");
Serial1.println();
Serial1.println("username=E***&pwd=A*********");
Serial1.println();
or this:
char postArray[167] = {0x50, 0x4F, 0x53, 0x54, 0x20, 0x2F, 0x6C, 0x6F, 0x67, 0x69, 0x6E, 0x41,
0x6A, 0x61, 0x78, 0x2F, 0x20, 0x48, 0x54, 0x54, 0x50, 0x2F, 0x31, 0x2E, 0x31, 0x0D, 0x0A, 0x48, 0x6F,
0x73, 0x74, 0x3A, 0x20, 0x64, 0x65, 0x76, 0x2D, 0x61, 0x71, 0x75, 0x68, 0x69, 0x76, 0x65, 0x64,
0x61, 0x74, 0x61, 0x2E, 0x68, 0x65, 0x72, 0x6F, 0x6B, 0x75, 0x61, 0x70, 0x70, 0x2E, 0x63, 0x6F, 0x6D,
0x0D, 0x0A, 0x43, 0x6F, 0x6E, 0x74, 0x65, 0x6E, 0x74, 0x2D, 0x54, 0x79, 0x70, 0x65, 0x3A, 0x20,
0x61, 0x70, 0x70, 0x6C, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6F, 0x6E, 0x2F, 0x78, 0x2D, 0x77, 0x77, 0x77,
0x2D, 0x66, 0x6F, 0x72, 0x6D, 0x2D, 0x75, 0x72, 0x6C, 0x65, 0x6E, 0x63, 0x6F, 0x64, 0x65, 0x64,
0x0D, 0x0A, 0x43, 0x6F, 0x6E, 0x74, 0x65, 0x6E, 0x74, 0x2D, 0x4C, 0x65, 0x6E, 0x67, 0x74, 0x68,
0x3A, 0x20, 0x32, 0x38, 0x0D, 0x0A, 0x0D, 0x0A, 0x75, 0x73, 0x65, 0x72, 0x6E, 0x61, 0x6D, 0x65,
0x3D, 0x45, 0x76, 0x61, 0x6E, 0x26, 0x70, 0x77, 0x64, 0x3D, 0x41, 0x71, 0x75, 0x61, 0x74, 0x65,
0x73, 0x74, 0x31, 0x32, 0x0D, 0x0A, 0x0D, 0x0A};
...
Serial1.write(postArray, 167);
and I am reading the response like this:
while(Serial1.available()) {
char c = Serial1.read();
Serial.print(c);
}