php - ESP8266 send GET request to remote server -
http://www.universalcard.byethost7.com server. kept index.php file. code given below
<?php if(isset($_get['username']) && isset($_get['pin']) && isset($_get['cost'])) { $username = $_get['username']; $pin = $_get['pin']; $cost = $_get['cost']; $filecontent = "username is: ".$username." , pin is: ".$pin." , cost is: ".$cost."\n"; $filestatus = file_put_contents('uc.txt',$filecontent,file_append); if($filestatus != false ) { echo "data written file.."; }else{ echo "ohh sorry.."; } } else { echo "something went wrong.."; } ?>
and want send request esp8266 arduino ide. in request, sending 3 variables 'username' , 'pin' , 'cost' values (data type string). , these values appending file "uc.txt". when send request using browser, values append text file.
but when tried send using esp8266 not appending
arduino code below
#include <esp8266wifi.h> #include <wificlientsecure.h> const char* ssid = "rainbow"; const char* password = "12345678"; const char* host = "universalcard.byethost7.com"; const int httpsport = 443; // use web browser view , copy // sha1 fingerprint of certificate //const char* fingerprint = "cf 05 98 89 ca ff 8e d8 5e 5c e0 c2 e4 f7 e6 c3 c7 50 dd 5c"; void setup() { serial.begin(115200); serial.println(); serial.print("connecting "); serial.println(ssid); wifi.begin(ssid, password); while (wifi.status() != wl_connected) { delay(500); serial.print("."); } serial.println(""); serial.println("wifi connected"); serial.println("ip address: "); serial.println(wifi.localip()); // use wificlientsecure class create tls connection wificlientsecure client; serial.print("connecting "); serial.println(host); if (!client.connect(host, httpsport)) { serial.println("connection failed"); return; } string url = "/index.php?username=2bv14is114&pin=5555&cost=1111"; serial.print("requesting url: "); serial.println(url); client.print(string("get ") + url + " http/1.1\r\n" + "host: " + host + "\r\n" + "user-agent: buildfailuredetectoresp8266\r\n" + "connection: close\r\n\r\n"); serial.println("request sent"); while (client.connected()) { string line = client.readstringuntil('\n'); if (line == "\r") { serial.println("headers received"); break; } } string line = client.readstringuntil('\n'); if (line.startswith("{\"state\":\"success\"")) { serial.println("esp8266/arduino ci successfull!"); } else { serial.println("esp8266/arduino ci has failed"); } serial.println("reply was:"); serial.println("=========="); serial.println(line); serial.println("=========="); serial.println("closing connection"); } void loop() { }
and output in serial monitor below
your host has sort of protection (maybe against bots), expects _test
cookie set javascript, if not present.
you acquire cookie, first visiting site browser , copy paste cookie code.
need same ip, esp8266 introduced server, since cookie ip bound.
in case have problem, if have dynamic ip , longevity of cookie unknown.
you acquire cookie parsing response, cookie aes encrypted , complicated.
the sensible solution switch host without such protection.
solution same problem in this , this question.
Comments
Post a Comment