mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
http2_request_example: Change the target http2 server to http2.github.io
and perform only a GET
request
This commit is contained in:
parent
045b38857d
commit
0b7ed763e4
@ -1,6 +1,55 @@
|
||||
# HTTP/2 Request Example
|
||||
|
||||
Established HTTP/2 connection with https://http2.golang.org
|
||||
- Performs a GET on /clockstream
|
||||
- Performs a PUT on /ECHO
|
||||
Establish an HTTP/2 connection with https://http2.github.io
|
||||
- Performs a GET on /index.html
|
||||
|
||||
## How to use example
|
||||
Before project configuration and build, be sure to set the correct chip target using `idf.py set-target <chip_name>`.
|
||||
|
||||
### Hardware Required
|
||||
|
||||
* A development board with ESP32/ESP32-S2/ESP32-C3 SoC (e.g., ESP32-DevKitC, ESP-WROVER-KIT, etc.)
|
||||
* A USB cable for power supply and programming
|
||||
|
||||
### Configure the project
|
||||
|
||||
```
|
||||
idf.py menuconfig
|
||||
```
|
||||
Open the project configuration menu (`idf.py menuconfig`) to configure Wi-Fi or Ethernet. See "Establishing Wi-Fi or Ethernet Connection" section in [examples/protocols/README.md](../../README.md) for more details.
|
||||
|
||||
### Build and Flash
|
||||
|
||||
Build the project and flash it to the board, then run monitor tool to view serial output:
|
||||
|
||||
```
|
||||
idf.py -p PORT flash monitor
|
||||
```
|
||||
|
||||
(Replace PORT with the name of the serial port to use.)
|
||||
|
||||
(To exit the serial monitor, type ``Ctrl-]``.)
|
||||
|
||||
See the Getting Started Guide for full steps to configure and use ESP-IDF to build projects.
|
||||
|
||||
## Example Output
|
||||
|
||||
```
|
||||
I (5609) example_connect: - IPv4 address: 192.168.0.103
|
||||
I (5609) example_connect: - IPv6 address: fe80:0000:0000:0000:ae67:b2ff:fe45:0194, type: ESP_IP6_ADDR_IS_LINK_LOCAL
|
||||
Connecting to server
|
||||
Connection done
|
||||
[get-response] <!DOCTYPE HTML>
|
||||
<html lang="en">
|
||||
.
|
||||
.
|
||||
.
|
||||
Body of index.html
|
||||
.
|
||||
.
|
||||
.
|
||||
.
|
||||
</html>
|
||||
[get-response] Frame fully received
|
||||
[get-response] Stream Closed
|
||||
```
|
||||
|
@ -1,3 +1,3 @@
|
||||
idf_component_register(SRCS "http2_request_example_main.c"
|
||||
INCLUDE_DIRS "."
|
||||
EMBED_TXTFILES "golang_root_cert.pem")
|
||||
EMBED_TXTFILES "http2_github_io_root_cert.pem")
|
||||
|
@ -2,4 +2,4 @@
|
||||
# "main" pseudo-component makefile.
|
||||
#
|
||||
# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.)
|
||||
COMPONENT_EMBED_TXTFILES := golang_root_cert.pem
|
||||
COMPONENT_EMBED_TXTFILES := http2_github_io_root_cert.pem
|
||||
|
@ -1,20 +0,0 @@
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIDSjCCAjKgAwIBAgIQRK+wgNajJ7qJMDmGLvhAazANBgkqhkiG9w0BAQUFADA/
|
||||
MSQwIgYDVQQKExtEaWdpdGFsIFNpZ25hdHVyZSBUcnVzdCBDby4xFzAVBgNVBAMT
|
||||
DkRTVCBSb290IENBIFgzMB4XDTAwMDkzMDIxMTIxOVoXDTIxMDkzMDE0MDExNVow
|
||||
PzEkMCIGA1UEChMbRGlnaXRhbCBTaWduYXR1cmUgVHJ1c3QgQ28uMRcwFQYDVQQD
|
||||
Ew5EU1QgUm9vdCBDQSBYMzCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEB
|
||||
AN+v6ZdQCINXtMxiZfaQguzH0yxrMMpb7NnDfcdAwRgUi+DoM3ZJKuM/IUmTrE4O
|
||||
rz5Iy2Xu/NMhD2XSKtkyj4zl93ewEnu1lcCJo6m67XMuegwGMoOifooUMM0RoOEq
|
||||
OLl5CjH9UL2AZd+3UWODyOKIYepLYYHsUmu5ouJLGiifSKOeDNoJjj4XLh7dIN9b
|
||||
xiqKqy69cK3FCxolkHRyxXtqqzTWMIn/5WgTe1QLyNau7Fqckh49ZLOMxt+/yUFw
|
||||
7BZy1SbsOFU5Q9D8/Rh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r01lYPf7TMSVcGDiEo+afgv2MW5gxTs14nhr9hctJqvIni5ly
|
||||
/D6q1UEL2tU2ob8cbkdJf17ZSHwD2f2LSaCYJkJA69aSEaRkCldUxPUd1gJea6zu
|
||||
xICaEnL6VpPX/78whQYwvwt/Tv9XBZ0k7YXDK/umdaisLRbvfXknsuvCnQsH6qqF
|
||||
0wGjIChBWUMo0oHjqvbsezt3tkBigAVBRQHvFwY+3sAzm2fTYS5yh+Rp/BIAV0Ae
|
||||
cPUeybQ=
|
||||
-----END CERTIFICATE-----
|
@ -1,6 +1,6 @@
|
||||
/* HTTP2 GET Example using nghttp2
|
||||
|
||||
Contacts http2.golang.org and executes the GET/PUT requests. A thin API
|
||||
Contacts http2.github.io and executes the GET request. A thin API
|
||||
wrapper on top of nghttp2, to properly demonstrate the interactions.
|
||||
|
||||
This example code is in the Public Domain (or CC0 licensed, at your option.)
|
||||
@ -26,15 +26,13 @@
|
||||
#include "sh2lib.h"
|
||||
|
||||
|
||||
extern const uint8_t server_root_cert_pem_start[] asm("_binary_golang_root_cert_pem_start");
|
||||
extern const uint8_t server_root_cert_pem_end[] asm("_binary_golang_root_cert_pem_end");
|
||||
extern const uint8_t server_root_cert_pem_start[] asm("_binary_http2_github_io_root_cert_pem_start");
|
||||
extern const uint8_t server_root_cert_pem_end[] asm("_binary_http2_github_io_root_cert_pem_end");
|
||||
|
||||
/* The HTTP/2 server to connect to */
|
||||
#define HTTP2_SERVER_URI "https://http2.golang.org"
|
||||
#define HTTP2_SERVER_URI "https://http2.github.io"
|
||||
/* A GET request that keeps streaming current time every second */
|
||||
#define HTTP2_STREAMING_GET_PATH "/clockstream"
|
||||
/* A PUT request that echoes whatever we had sent to it */
|
||||
#define HTTP2_PUT_PATH "/ECHO"
|
||||
#define HTTP2_STREAMING_GET_PATH "/index.html"
|
||||
|
||||
|
||||
int handle_get_response(struct sh2lib_handle *handle, const char *data, size_t len, int flags)
|
||||
@ -120,10 +118,6 @@ static void http2_task(void *args)
|
||||
|
||||
/* HTTP GET */
|
||||
sh2lib_do_get(&hd, HTTP2_STREAMING_GET_PATH, handle_get_response);
|
||||
|
||||
/* HTTP PUT */
|
||||
sh2lib_do_put(&hd, HTTP2_PUT_PATH, send_put_data, handle_echo_response);
|
||||
|
||||
while (1) {
|
||||
/* Process HTTP2 send/receive */
|
||||
if (sh2lib_execute(&hd) < 0) {
|
||||
|
Loading…
Reference in New Issue
Block a user