http post in https_request example

Reeshma
Posts: 37
Joined: Tue Mar 28, 2017 12:40 pm

http post in https_request example

Postby Reeshma » Thu Jun 01, 2017 4:21 am

I have tried the http post from https_request example..but am getting the following error , can anyone please say , where am made a mistake...in https_request code in order to post the data from esp32 to webserver...

[0;32mI (30082) example: Starting again![0m
[0;32mI (30082) example: Connected to AP[0m
[0;32mI (30082) example: Connecting to xxxxxxxxx.com:443...[0m
[0;32mI (30322) example: Connected.[0m
[0;32mI (30322) example: Performing the SSL/TLS handshake...[0m
[0;32mI (32422) example: Verifying peer X.509 certificate...[0m
[0;33mW (32422) example: Failed to verify peer certificate![0m
[0;33mW (32422) example: verification info: ! The certificate is not correctly signed by the trusted CA
[0m
[0;32mI (32432) example: Writing HTTP request...[0m
[0;32mI (32442) example: 327 bytes written[0m
[0;32mI (32442) example: Reading HTTP response...[0m
[0;32mI (32442) example: in do while....[0m
[0;32mI (32682) example: 384 bytes written[0m
HTTP/1.1 400 Bad Request

Server: nginx

Date: Thu, 01 Jun 2017 04:06:55 GMT

Content-Type: text/html

Content-Length: 166

Connection: close

Strict-Transport-Security: max-age=31556926; includeSubDomains; preload



<html>

<head><title>400 Bad Request</title></head>

<body bgcolor="white">

<center><h1>400 Bad Request</h1></center>

<hr><center>nginx</center>

</body>

</html>

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: http post in https_request example

Postby WiFive » Thu Jun 01, 2017 5:47 am

What did you change in the example?

Reeshma
Posts: 37
Joined: Tue Mar 28, 2017 12:40 pm

Re: http post in https_request example

Postby Reeshma » Thu Jun 01, 2017 7:22 am

I have changed in this section only..
static const char *REQUEST = "POST" WEB_URL " HTTP/1.0\r\n"
"Host: "WEB_SERVER"\r\n"
"{\"pwr\":\"off\"}\r\n"
"content-Type:application/json\r\n"
"content-Length:13\r\n"
"connection:close\r\n"
"User-Agent: esp-idf/1.0 esp32\r\n"
"\r\n";
the rest of the code is the same..
sorry , am a beginner to this platform....i dont know, can you please say..where will am need to change in the code..?
i can able to get the data from server using get in https_request code....
i didn find any example regarding the http post using https_request...can you help me..

ESP_igrr
Posts: 2072
Joined: Tue Dec 01, 2015 8:37 am

Re: http post in https_request example

Postby ESP_igrr » Thu Jun 01, 2017 7:49 am

the ""{\"pwr\":\"off\"}\r\n"" should come after all the headers and the newline (\r\n), not in between the headers.

Reeshma
Posts: 37
Joined: Tue Mar 28, 2017 12:40 pm

Re: http post in https_request example

Postby Reeshma » Thu Jun 01, 2017 8:53 am

Thanks for your reply sir ,
i have made changes based on your suggestion...is it right..??

static const char *REQUEST = "POST" WEB_URL " HTTP/1.0\r\n"
"Host: "WEB_SERVER"\r\n"
"User-Agent: esp-idf/1.0 esp32\r\n"
"content-Type:application/json"
"content-Length:13"
"{\"pwr\":\"off\"}\r\n"
"\r\n";
but am getting the same error

0;32mI (16362) example: Starting again![0m
[0;32mI (16362) example: Connected to AP[0m
[0;32mI (16362) example: Connecting to zbliss-home.firebaseio.com:443...[0m
[0;32mI (18112) example: Connected.[0m
[0;32mI (18112) example: Performing the SSL/TLS handshake...[0m
[0;32mI (20212) example: Verifying peer X.509 certificate...[0m
[0;33mW (20212) example: Failed to verify peer certificate![0m
[0;33mW (20212) example: verification info: ! The certificate is not correctly signed by the trusted CA
[0m
[0;32mI (20222) example: Writing HTTP request...[0m
[0;32mI (20232) example: 305 bytes written[0m
[0;32mI (20232) example: Reading HTTP response...[0m
[0;32mI (20462) example: 384 bytes read[0m
HTTP/1.1 400 Bad Request

Server: nginx

Date: Thu, 01 Jun 2017 08:49:42 GMT

Content-Type: text/html

Content-Length: 166

Connection: close

Strict-Transport-Security: max-age=31556926; includeSubDomains; preload



<html>

<head><title>400 Bad Request</title></head>

<body bgcolor="white">

<center><h1>400 Bad Request</h1></center>

<hr><center>nginx</center>

</body>

</html>
can you please say....where am need to make changes in the https_request code.

kurtzweber
Posts: 64
Joined: Tue Jan 10, 2017 1:09 pm

Re: http post in https_request example

Postby kurtzweber » Thu Jun 01, 2017 9:04 am

Reeshma give a look to the HTTP protocol specs:
https://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html

Code: Select all

Request       = Request-Line              ; Section 5.1
                        *(( general-header        ; Section 4.5
                         | request-header         ; Section 5.3
                         | entity-header ) CRLF)  ; Section 7.1
                        CRLF
                        [ message-body ]          ; Section 4.3
you have to put all the headers first, then add a blank line ("CRLF") and after that line add your body {\"pwr\":\"off\"}

Reeshma
Posts: 37
Joined: Tue Mar 28, 2017 12:40 pm

Re: http post in https_request example

Postby Reeshma » Thu Jun 01, 2017 9:31 am

Thank you sir, i have made changes given in that link...but still am getting the same error.
here am attaching the changes that i have made.

static const char *REQUEST = "POST" WEB_URL " HTTP/1.0\r\n"
"User-Agent: esp-idf/1.0 esp32\r\n"
"connection:close" //general header
"Host: WEB_SERVER" //request header
"content-Type:application/json" //entity header
"content-Length:13\r\n" //entity header
"\r\n"
"{\"pwr\":\"off\"}";
is it right...?? can you please say..where am made a mistake.

kurtzweber
Posts: 64
Joined: Tue Jan 10, 2017 1:09 pm

Re: http post in https_request example

Postby kurtzweber » Thu Jun 01, 2017 12:58 pm

Hi

use a tool like Fiddler or some browser extensions to "sniff" the real request the browser send and implement the same in your code

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: http post in https_request example

Postby WiFive » Thu Jun 01, 2017 1:42 pm

Code: Select all

static const char *REQUEST = "POST" WEB_URL " HTTP/1.0\r\n"
"User-Agent: esp-idf/1.0 esp32\r\n"
"Connection: close\r\n" //general header
"Host: WEB_SERVER\r\n" //request header
"Content-Type: application/json\r\n" //entity header
"Content-Length: 13\r\n" //entity header
"\r\n"
"{\"pwr\":\"off\"}";

Reeshma
Posts: 37
Joined: Tue Mar 28, 2017 12:40 pm

Re: http post in https_request example

Postby Reeshma » Fri Jun 02, 2017 10:14 am

Thank you all ,who gave an idea to post the data to webserver using https_request example code.Now i can able to update the data from esp32 to webserver.... :D
Here is my log

[0;32mI (71152) example: Starting again![0m
[0;32mI (71152) example: Connected to AP[0m
[0;32mI (71152) example: Connecting to http://www.xxxx.com:443...[0m
[0;32mI (71172) example: Connected.[0m
[0;32mI (71172) example: Performing the SSL/TLS handshake...[0m
[0;32mI (72722) example: Verifying peer X.509 certificate...[0m
[0;33mW (72722) example: Failed to verify peer certificate![0m
[0;33mW (72722) example: verification info: ! The certificate is not correctly signed by the trusted CA
[0m
[0;32mI (72732) example: Writing HTTP request...[0m
[0;32mI (72742) example: request=[POST https://www.xxxxx.com/identitytoolkit/v ... RxXywCGcsc HTTP/1.1
Host: http://www.xxxxx.com
User-Agent: esp-idf/1.0 esp32
Connection:close
Cache-Control:no-cache
Accept:application/json
Content-Type:application/json
Content-Length:82

{'email':'xxxx.com','password':'yyyyy','returnSecureToken':fffff}[0m
[0;32mI (72822) example: 384 bytes written[0m
[0;32mI (72832) example: Reading HTTP response...[0m
[0;32mI (73392) example: 511 bytes read[0m
HTTP/1.1 200 OK

Cache-Control: no-cache, no-store, max-age=0, must-revalidate

Pragma: no-cache

Expires: Mon, 01 Jan 1990 00:00:00 GMT

Date: Fri, 02 Jun 2017 09:28:51 GMT

Vary: X-Origin

Content-Type: application/json; charset=UTF-8

X-Content-Type-Options: nosniff

X-Frame-Options: SAMEORIGIN

X-XSS-Protection: 1; mode=block

Server: GSE

Alt-Svc: quic=":443"; ma=2592000; v="38,37,36,35"

Accept-Ranges: none

Vary: Origin,Accept-Encoding

Connection: close



{
"kind": "identitytoolkit#VerifyPassword[0;32mI (73422) example: 511 bytes read[0m
Response",
"localId": "SAiWtdSkHRbDBUVklcu2sujqzCX2",
"email": "xxx.com",
"displayName": "",
"idToken":
}

Who is online

Users browsing this forum: Google [Bot] and 108 guests