Receiving 400 Bad Request

General discussion on mikroPascal PRO for PIC.
Post Reply
Author
Message
PeetH
Posts: 20
Joined: 25 Mar 2019 19:40

Receiving 400 Bad Request

#1 Post by PeetH » 15 Apr 2020 16:49

I want to read the content of a text file on my own website, with an ESP-01 connected to PIC18F4550 using AT commands. I do not have any problem connecting to the wifi or starting a TCP connection with the webserver. But I could not manage the right code for the webserver to respond with the content of the file. I use the serial monitor to read all the responses.

When I use the following statement, I do get the bad request error :
UART1_Write_Text('AT+CIPSEND=41');
UART1_Write(0x0D);
UART1_Write(0x0A);
Delay_ms(1000);
UART1_Write_Text('GET /LEDstate.txt');
UART1_Write(0x0D);
UART1_Write(0x0A);
UART1_Write_Text('Host: xxx.xxx.xx.xxx'); // xxx... is the ip of my dedicated server
UART1_Write(0x0D);
UART1_Write(0x0A);

OK
WIFI CONNECTED
AT+CIPRECMODE=0
ERROR
AT+CWMODE=3
OK
WIFI GOT IP
AT+CIPMUX=0
WIFI DISCONNECT
WIFI CONNECTED
AT+CWJAP="yyyyyyyy","zzzzzz" // yy.. = ssid, zzz.. = passw
busy p...
WIFI GOT IP
OK
AT+CIFSR
+CIFSR:APIP,"192.168.4.1"
+CIFSR:APMAC,"ce:50:e3:c0:2f:df"
+CIFSR:STAIP,"10.0.0.12"
+CIFSR:STAMAC,"cc:50:e3:c0:2f:df"
OK
AT+CIPSTART="TCP","xxx.xxx.xx.xxx",80 //xxx.xxx.xx.xxx contain my actual ip of dedicated server
CONNECT
OK
AT+CIPMODE=0
OK
AT+CIPSEND=41
OK
>
Recv 41 bytes
SEND OK

+IPD,919:HTTP/1.1 400 Bad Request
Connection: close
Cache-Control: private, no-cache, no-store, must-revalidate, max-age=0
Pragma: no-cache
Content-Type: text/html
Content-Length: 680
Date: Wed, 15 Apr 2020 15:29:12 GMT
Server: LiteSpeed
<!DOCTYPE html>
<html style="height:100%">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" >
<title> 400 Bad Request
</title></head>
<body style="color: #444; margin:0;font: normal 14px/20px Arial, Helvetica, sans-serif; height:100%; background-color: #fff;">
<div style="height:auto; min-height:100%; "> <div style="text-align: center; width:800px; margin-left: -400px; position:absolute; top: 30%; left:50%;">
<h1 style="margin:0; font-size:150px; line-height:150px; font-weight:bold;">400</h1>
<h2 style="margin-top:20px;font-size: 30px;">Bad Request
</h2>
<p>It is not a valid request!</p>
</div></div></body></html>
CLOSED

When I replace the GET statement, I do not get any errors, but I also do not get any response with the data in it :
UART1_Write_Text('GET /LEDstate.txt HTTP/1.1'); // just HTTP/1.1 added

The last few responses...
OK
AT+CIPMODE=0
OK
AT+CIPSEND=50
OK
>
Recv 50 bytes
SEND OK
No other responses are received!.
Help will be much appreciated. I am also not getting it right to run a php file on the server with POST, but believe if this one is solved, it may help me with the next problem.

PeetH
Posts: 20
Joined: 25 Mar 2019 19:40

Re: Receiving 400 Bad Request

#2 Post by PeetH » 16 Apr 2020 08:20

What I have just noted is, that I do not see the GET command in the echo responses. I do not know why?

PeetH
Posts: 20
Joined: 25 Mar 2019 19:40

Re: Receiving 400 Bad Request

#3 Post by PeetH » 23 Apr 2020 15:30

I solve the problem thank you

Post Reply

Return to “mikroPascal PRO for PIC General”