-->
Page 1 of 1

ESP8266 + local server = 400 Bad Request

PostPosted: Mon Mar 06, 2017 6:04 am
by jakubst
I'm using ESP8266 with actual firmware ESP8266_NONOS_SDK_V2.0.0_16_08_10.
I do database query to PHP + MySQL using at commands.

On Internet network

... ESP8266 works fine for example: zzzzzzz.zzzzzzzzz.zz/dodaj_rek.php?n=129&u=1488723073&d=-51&s=203

AT+CWMODE_CUR=3
AT+CIPSTART="TCP","zzzzzzz.zzzzzzzzz.zz",80
AT+CIPSEND=89
GET dodaj_rek.php?n=129&u=1488723073&d=-51&s=203 HTTP/1.1\r\nHost: zzzzzzz.zzzzzzzzz.zz\r\n\r\n

server answer:

+IPD,189:HTTP/1.1 200 OK
Date: Mon, 06 Mar 2017 02:29:39 GMT
Server: Apache/2
X-Powered-By: PHP/5.3.29
Vary: User-Agent
Content-Length: 11
Content-Type: text/html; charset=UTF-8
CLOSED

and new rekord in database has been added coorectly.


Server in local network

I installed actual version of Apache, PHP and MySQL on computer with Win10(64-bit) and IP 192.168.1.51 listenning on port 80.
SSL is not enabled.

When I'm using such url:

192.168.1.51/dodaj_rek.php?n=129&u=1488723073&d=-51&s=203

in web browser of any machine (computer, smartfon, tablet) in my local network via WiFi or LAN, every thing works fine.

Problem arises when i'm trying do the same using ESP8266.

AT+CWMODE_CUR=3
AT+CIPSTART="TCP","192.168.1.51",80
AT+CIPSEND=81
GET dodaj_rek.php?n=129&u=1488723073&d=-51&s=203 HTTP/1.1\r\nHost: 192.168.1.51\r\n\r\n


AT+CIPSTART responds correctly connecting to the server
AT+CIPOSEND responds correctly showing prompt: >
After sending GET responds:

Recv 81 bytes

SEND OK

but server generates error: 400 Bad Request

+IPD,418:HTTP/1.1 400 Bad Request
Date: Mon, 06 Mar 2017 02:40:29 GMT
Server: Apache/2.4.25 (Win64) PHP/5.6.30
Content-Length: 226
Connection: close
Content-Type: text/html; charset=iso-8859-1
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>400 Bad Request</title>
</head><body>
<h1>Bad Request</h1>
<p>Your browser sent a request that this server could not understand.<br /></p>
</body></html>
CLOSED


I attach configuration files of PHP and Apache.

I spent a lot of time and I can not find the reason :(

Re: ESP8266 + local server = 400 Bad Request

PostPosted: Wed Mar 08, 2017 1:32 pm
by jeffas
There must be something different between the request sent by your browser and the one sent by the ESP.
I suggest doing a packet capture on your server (e.g. wireshark) and compare the working and non-working requests.
Or you might be able to increase the log level on your server, to get more detail about what it doesn't like.

Re: ESP8266 + local server = 400 Bad Request

PostPosted: Wed Mar 08, 2017 3:16 pm
by xl97
What happens when you omit the 1.1 protocol params?

HTTP/1.1\r\nHost: 192.168.1.51\r\n\r\n


Or maybe try 1.0 and omit the HOST param..

something is being malformed when your URL request..