Unable to do HTTP POST on PLIVO using ESP8266
Posted: Sun Jul 31, 2016 1:51 am
Hey Guys,
I am working on a project in which I need to send one SMS if the Input pin is active(logic 1). I have to use PLIVO for sending sms and that sms can be sent by doing HTTP POST on the given URL by the plivo.
https://www.plivo.com/docs/api/message/
I am able to send HTTP POST on servers like thingspeak.com, experttexting.com and some http test servers but not on PLIVO Server.
I am able to send HTTP POST on PLIVO from web clients like POSTMAN, POSTER and HTTPRequester but not from the ESP8266 module.
Here is the raw transaction log from POSTMAN for successful SMS Sent.
This is a raw transaction log from HTTPRequester..
This is how I am posting from my ESP8266..
After connecting to the WiFi router..
I am not getting any response from the server. Am I missing something? Please help guys..
I am working on a project in which I need to send one SMS if the Input pin is active(logic 1). I have to use PLIVO for sending sms and that sms can be sent by doing HTTP POST on the given URL by the plivo.
https://www.plivo.com/docs/api/message/
I am able to send HTTP POST on servers like thingspeak.com, experttexting.com and some http test servers but not on PLIVO Server.
I am able to send HTTP POST on PLIVO from web clients like POSTMAN, POSTER and HTTPRequester but not from the ESP8266 module.
Here is the raw transaction log from POSTMAN for successful SMS Sent.
Code: Select all
POST /v1/Account/MYAUTHID/Message/ HTTP/1.1
Host: api.plivo.com
Content-Type: application/json
Authorization: Basic TUFaSkRITldaSFlUS1dNVFZIWU06TXpSaU1XWm1OVGxrTmpGaE9XTmhOelJpWTJRMU5EaGlaR0ZqWVRKag==
Cache-Control: no-cache
Postman-Token: 02b0f9b7-234a-bc21-42c4-eb66c579a99d
{
"src" : "+13303623231",
"dst" : "+17133028183",
"text" : "Hi from PLIVO"
}
This is a raw transaction log from HTTPRequester..
Code: Select all
POST https://api.plivo.com/v1/Account/MYAUTHID/Message/
Authorization: Basic
Content-Type: application/json
Username: MYUSERNAME
{
"src" : "+13303623231",
"dst" : "+17133028183",
"text" : "Hi from PLIVO"
}
This is how I am posting from my ESP8266..
After connecting to the WiFi router..
Code: Select all
const char * host = "api.plivo.com";
void loop(void)
{
/* Check if module is connected to the Server */
if (client.connect(host, 80))
{
Serial.print("Connected to ");
Serial.println(host);
SendSMS();
CheckServerResponse();
}
}
void SendSMS(void)
{
String body = "{\n\"src\" : \"+13303623231\",\n\"dst\" : \"+17133028183\",\n\"text\" : \"Input 1 Triggered, Alert from Salman via PLIVO on 31/07/2016\"\n}";
client.print("POST https://api.plivo.com/v1/Account/MYAUTID/Message/");
client.print("Authorization: Basic\n");
client.print("Content-Type: application/json\n");
client.print("Username: MYAUTHID\n");
client.print("\n");
client.print(body);
}
void CheckServerResponse(void)
{
Serial.println("Server Response....");
/* Read all the lines of the reply from server and print them to Serial */
while(client.available()){
String line = client.readStringUntil('\r');
Serial.print(line);
}
}
I am not getting any response from the server. Am I missing something? Please help guys..