Re: Unable to do HTTP POST on PLIVO using ESP8266
Posted:
Mon Aug 01, 2016 3:55 pm
by martinayotte
Good catch ! (I didn't even saw this mistake ...)
Also, although not related to the problem, a good suggestion is avoid doing many client.print() calls, it is better to concatenate multiple lines into a String and get it sent with a single client.print().
Re: Unable to do HTTP POST on PLIVO using ESP8266
Posted:
Tue Aug 02, 2016 2:35 am
by salmanali11053
bbx10node wrote:Code: Select all client.print("POST https://api.plivo.com/v1/Account/MYAUTID/Message/");
client.print("Authorization: Basic\n");
The first line does not end with newline.
If adding a newline does not work, I would start capturing packets using tcpdump or wireshark to see what is really going on. I use a Linux firewall so it is possible to capture packets going to/from the Internet. I do know how you can do this using a regular WiFi router.
Hey I have tried adding new line too. I have tried these many things but no success at all.. Even plivo support doesn't reply me for this problem.
Code: Select allString body = "\n{\n\"src\" : \"+13303623231\",\n\"dst\" : \"+17133028183\",\n\"text\" : \"Input 1 Triggered,2nd Alert Msg from ESP8266 via PLIVO on 1/08/2016\"\n}";
client.print("POST /v1/Account/MYAUTHID/Message/ HTTP/1.1\n");
client.print("Host: api.plivo.com\n");
client.print("Content-Type: application/json\n");
client.print("Authorization: Basic TUFaSkRITldaSFlUS1dNVFZIWU06TXpSaU1XWm1OVGxrTmpGaE9XTmhOelJpWTJRMU5EaGlaR0ZqWVRKag==\n");
client.print("Cache-Control: no-cache\n");
client.print("Postman-Token: 02b0f9b7-234a-bc21-42c4-eb66c579a99d\n");
client.print("Content-Length: ");
client.print(body.length());
client.print(body);
I have tried this too
Code: Select all http.begin("https://api.plivo.com/v1/Account/MAZJDHNWZHYTKWMTVHYM/Message/");
http.setAuthorization("MYAUTHID(Username)","MYTOKENNUMBER(Pass)");
http.addHeader("Content-Type","application/json");
http.POST(body);
http.writeToStream(&Serial);
http.end();
CheckServerResponse();
please help me someone. I am about to give up
Re: Unable to do HTTP POST on PLIVO using ESP8266
Posted:
Tue Aug 02, 2016 12:16 pm
by martinayotte
I've just seen other potential glitches :
First, you are sending the body variable right after sending the content length. So the header ending is missing, you should send 2 times CRLF.
Second, maybe the fact you are sending only CR without LF, it could be another issue.
Re: Unable to do HTTP POST on PLIVO using ESP8266
Posted:
Thu Aug 04, 2016 2:31 am
by salmanali11053
martinayotte wrote:I've just seen other potential glitches :
First, you are sending the body variable right after sending the content length. So the header ending is missing, you should send 2 times CRLF.
Second, maybe the fact you are sending only CR without LF, it could be another issue.
I've tried doing this too. Now I am getting a status code as 301 Moved Permanently. If I change the HTTP request from POST to GET I am getting 400 Bad Request. Any idea why I am getting 301 ?