| <!DOCTYPE html> |
| <html lang="en" data-base-path="/cpp-httplib"> |
| <head> |
| <meta charset="utf-8"> |
| <meta name="viewport" content="width=device-width, initial-scale=1"> |
| <title>HTTPS Client - cpp-httplib</title> |
| <link rel="icon" type="image/svg+xml" href="/cpp-httplib/favicon.svg"> |
| <link rel="stylesheet" href="/cpp-httplib/css/main.css"> |
| <script> |
| (function() { |
| var t = localStorage.getItem('preferred-theme'); |
| if (!t) t = window.matchMedia('(prefers-color-scheme: light)').matches ? 'light' : 'dark'; |
| if (t === 'light') document.documentElement.setAttribute('data-theme', 'light'); |
| })(); |
| </script> |
| </head> |
| <body> |
| <header class="header"> |
| <div class="header-inner"> |
| <a href="/cpp-httplib/en/" class="header-title">cpp-httplib <span style="font-size:0.75em;font-weight:normal;margin-left:4px">v0.36.0</span></a> |
| <div class="header-spacer"></div> |
| <nav class="header-nav"> |
| <a href="/cpp-httplib/en/"> |
| <svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 9l9-7 9 7v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"/><polyline points="9 22 9 12 15 12 15 22"/></svg> |
| Home |
| </a> |
| |
| |
| <a href="/cpp-httplib/en/tour/"> |
| <svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><polygon points="16.24 7.76 14.12 14.12 7.76 16.24 9.88 9.88 16.24 7.76"/></svg> |
| Tour |
| </a> |
| |
| |
| |
| <a href="https://github.com/yhirose/cpp-httplib" aria-label="GitHub"> |
| <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M9 19c-5 1.5-5-2.5-7-3m14 6v-3.87a3.37 3.37 0 0 0-.94-2.61c3.14-.35 6.44-1.54 6.44-7A5.44 5.44 0 0 0 20 4.77 5.07 5.07 0 0 0 19.91 1S18.73.65 16 2.48a13.38 13.38 0 0 0-7 0C6.27.65 5.09 1 5.09 1A5.07 5.07 0 0 0 5 4.77a5.44 5.44 0 0 0-1.5 3.78c0 5.42 3.3 6.61 6.44 7A3.37 3.37 0 0 0 9 18.13V22"/></svg> |
| GitHub |
| </a> |
| |
| |
| </nav> |
| <div class="header-tools"> |
| <button class="search-btn" aria-label="Search (⌘K)"> |
| <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="11" cy="11" r="8"/><line x1="21" y1="21" x2="16.65" y2="16.65"/></svg> |
| </button> |
| <button class="theme-toggle" aria-label="Toggle theme"></button> |
| |
| <div class="lang-selector"> |
| <button class="lang-btn" aria-label="Language"> |
| <svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><line x1="2" y1="12" x2="22" y2="12"/><path d="M12 2a15.3 15.3 0 0 1 4 10 15.3 15.3 0 0 1-4 10 15.3 15.3 0 0 1-4-10 15.3 15.3 0 0 1 4-10z"/></svg> |
| EN |
| </button> |
| <ul class="lang-popup"> |
| |
| <li><a href="#" data-lang="en">EN</a></li> |
| |
| <li><a href="#" data-lang="ja">JA</a></li> |
| |
| </ul> |
| </div> |
| |
| </div> |
| <button class="sidebar-toggle" aria-label="Menu">☰</button> |
| </div> |
| </header> |
| |
| |
| |
| <div class="layout has-sidebar"> |
| |
| <aside class="sidebar"> |
| <nav class="sidebar-nav"> |
| |
| <div class="nav-section"> |
| <a href="/cpp-httplib/en/tour/" class="nav-section-title active">A Tour of cpp-httplib</a> |
| |
| <ul class="nav-list"> |
| |
| <li><a href="/cpp-httplib/en/tour/01-getting-started/" class="">Getting Started</a></li> |
| |
| <li><a href="/cpp-httplib/en/tour/02-basic-client/" class="">Basic Client</a></li> |
| |
| <li><a href="/cpp-httplib/en/tour/03-basic-server/" class="">Basic Server</a></li> |
| |
| <li><a href="/cpp-httplib/en/tour/04-static-file-server/" class="">Static File Server</a></li> |
| |
| <li><a href="/cpp-httplib/en/tour/05-tls-setup/" class="">TLS Setup</a></li> |
| |
| <li><a href="/cpp-httplib/en/tour/06-https-client/" class="active">HTTPS Client</a></li> |
| |
| <li><a href="/cpp-httplib/en/tour/07-https-server/" class="">HTTPS Server</a></li> |
| |
| <li><a href="/cpp-httplib/en/tour/08-websocket/" class="">WebSocket</a></li> |
| |
| <li><a href="/cpp-httplib/en/tour/09-whats-next/" class="">What's Next</a></li> |
| |
| </ul> |
| |
| </div> |
| |
| </nav> |
| </aside> |
| <main class="content"> |
| <article> |
| <h1>HTTPS Client</h1> |
| <p>In the previous chapter, you set up OpenSSL. Now let's put it to use with an HTTPS client. You can use the same <code>httplib::Client</code> from Chapter 2. Just pass a URL with the <code>https://</code> scheme to the constructor.</p> |
| <h2>GET Request</h2> |
| <p>Let's try accessing a real HTTPS site.</p> |
| <div class="code-block-wrapper"><div data-code-theme="dark"><pre style="background-color:#2b303b;"> |
| <span style="color:#b48ead;">#define </span><span style="color:#c0c5ce;">CPPHTTPLIB_OPENSSL_SUPPORT |
| </span><span style="color:#b48ead;">#include </span><span style="color:#c0c5ce;">"</span><span style="color:#a3be8c;">httplib.h</span><span style="color:#c0c5ce;">" |
| </span><span style="color:#b48ead;">#include </span><span style="color:#c0c5ce;"><</span><span style="color:#a3be8c;">iostream</span><span style="color:#c0c5ce;">> |
| </span><span style="color:#c0c5ce;"> |
| </span><span style="color:#b48ead;">int </span><span style="color:#8fa1b3;">main</span><span style="color:#c0c5ce;">() { |
| </span><span style="color:#c0c5ce;"> httplib::Client </span><span style="color:#8fa1b3;">cli</span><span style="color:#c0c5ce;">("</span><span style="color:#a3be8c;">https://nghttp2.org</span><span style="color:#c0c5ce;">"); |
| </span><span style="color:#c0c5ce;"> |
| </span><span style="color:#c0c5ce;"> </span><span style="color:#b48ead;">auto</span><span style="color:#c0c5ce;"> res = cli.</span><span style="color:#8fa1b3;">Get</span><span style="color:#c0c5ce;">("</span><span style="color:#a3be8c;">/</span><span style="color:#c0c5ce;">"); |
| </span><span style="color:#c0c5ce;"> </span><span style="color:#b48ead;">if </span><span style="color:#c0c5ce;">(res) { |
| </span><span style="color:#c0c5ce;"> std::cout << res-></span><span style="color:#bf616a;">status </span><span style="color:#c0c5ce;"><< std::endl; </span><span style="color:#65737e;">// 200 |
| </span><span style="color:#c0c5ce;"> std::cout << res-></span><span style="color:#bf616a;">body</span><span style="color:#c0c5ce;">.</span><span style="color:#8fa1b3;">substr</span><span style="color:#c0c5ce;">(</span><span style="color:#d08770;">0</span><span style="color:#c0c5ce;">, </span><span style="color:#d08770;">100</span><span style="color:#c0c5ce;">) << std::endl; </span><span style="color:#65737e;">// First 100 chars of the HTML |
| </span><span style="color:#c0c5ce;"> } </span><span style="color:#b48ead;">else </span><span style="color:#c0c5ce;">{ |
| </span><span style="color:#c0c5ce;"> std::cout << "</span><span style="color:#a3be8c;">Error: </span><span style="color:#c0c5ce;">" << </span><span style="color:#8fa1b3;">httplib::to_string</span><span style="color:#c0c5ce;">(res.</span><span style="color:#8fa1b3;">error</span><span style="color:#c0c5ce;">()) << std::endl; |
| </span><span style="color:#c0c5ce;"> } |
| </span><span style="color:#c0c5ce;">} |
| </span></pre> |
| </div><div data-code-theme="light"><pre style="background-color:#ffffff;"> |
| <span style="font-weight:bold;color:#a71d5d;">#define </span><span style="color:#323232;">CPPHTTPLIB_OPENSSL_SUPPORT |
| </span><span style="font-weight:bold;color:#a71d5d;">#include </span><span style="color:#183691;">"httplib.h" |
| </span><span style="font-weight:bold;color:#a71d5d;">#include </span><span style="color:#183691;"><iostream> |
| </span><span style="color:#323232;"> |
| </span><span style="font-weight:bold;color:#a71d5d;">int </span><span style="font-weight:bold;color:#795da3;">main</span><span style="color:#323232;">() { |
| </span><span style="color:#323232;"> httplib::Client cli(</span><span style="color:#183691;">"https://nghttp2.org"</span><span style="color:#323232;">); |
| </span><span style="color:#323232;"> |
| </span><span style="color:#323232;"> </span><span style="font-weight:bold;color:#a71d5d;">auto</span><span style="color:#323232;"> res </span><span style="font-weight:bold;color:#a71d5d;">=</span><span style="color:#323232;"> cli.Get(</span><span style="color:#183691;">"/"</span><span style="color:#323232;">); |
| </span><span style="color:#323232;"> </span><span style="font-weight:bold;color:#a71d5d;">if </span><span style="color:#323232;">(res) { |
| </span><span style="color:#323232;"> std::cout </span><span style="font-weight:bold;color:#a71d5d;"><<</span><span style="color:#323232;"> res->status </span><span style="font-weight:bold;color:#a71d5d;"><<</span><span style="color:#323232;"> std::endl; </span><span style="font-style:italic;color:#969896;">// 200 |
| </span><span style="color:#323232;"> std::cout </span><span style="font-weight:bold;color:#a71d5d;"><<</span><span style="color:#323232;"> res->body.substr(</span><span style="color:#0086b3;">0</span><span style="color:#323232;">, </span><span style="color:#0086b3;">100</span><span style="color:#323232;">) </span><span style="font-weight:bold;color:#a71d5d;"><<</span><span style="color:#323232;"> std::endl; </span><span style="font-style:italic;color:#969896;">// First 100 chars of the HTML |
| </span><span style="color:#323232;"> } </span><span style="font-weight:bold;color:#a71d5d;">else </span><span style="color:#323232;">{ |
| </span><span style="color:#323232;"> std::cout </span><span style="font-weight:bold;color:#a71d5d;"><< </span><span style="color:#183691;">"Error: " </span><span style="font-weight:bold;color:#a71d5d;"><< </span><span style="color:#323232;">httplib::to_string(res.error()) </span><span style="font-weight:bold;color:#a71d5d;"><<</span><span style="color:#323232;"> std::endl; |
| </span><span style="color:#323232;"> } |
| </span><span style="color:#323232;">} |
| </span></pre> |
| </div></div> |
| <p>In Chapter 2, you wrote <code>httplib::Client cli("http://localhost:8080")</code>. All you need to change is the scheme to <code>https://</code>. Every API you learned in Chapter 2 -- <code>Get()</code>, <code>Post()</code>, and so on -- works exactly the same way.</p> |
| <div class="code-block-wrapper"><div data-code-theme="dark"><pre style="background-color:#2b303b;"> |
| <span style="color:#8fa1b3;">curl</span><span style="color:#c0c5ce;"> https://nghttp2.org/ |
| </span></pre> |
| </div><div data-code-theme="light"><pre style="background-color:#ffffff;"> |
| <span style="color:#323232;">curl https://nghttp2.org/ |
| </span></pre> |
| </div></div> |
| <h2>Specifying a Port</h2> |
| <p>The default port for HTTPS is 443. If you need a different port, include it in the URL.</p> |
| <div class="code-block-wrapper"><div data-code-theme="dark"><pre style="background-color:#2b303b;"> |
| <span style="color:#c0c5ce;">httplib::Client </span><span style="color:#8fa1b3;">cli</span><span style="color:#c0c5ce;">("</span><span style="color:#a3be8c;">https://localhost:8443</span><span style="color:#c0c5ce;">"); |
| </span></pre> |
| </div><div data-code-theme="light"><pre style="background-color:#ffffff;"> |
| <span style="color:#323232;">httplib::Client </span><span style="font-weight:bold;color:#795da3;">cli</span><span style="color:#323232;">(</span><span style="color:#183691;">"https://localhost:8443"</span><span style="color:#323232;">); |
| </span></pre> |
| </div></div> |
| <h2>CA Certificate Verification</h2> |
| <p>When connecting over HTTPS, <code>httplib::Client</code> verifies the server certificate by default. It only connects to servers whose certificate was issued by a trusted CA (Certificate Authority).</p> |
| <p>CA certificates are loaded automatically from the Keychain on macOS, the system CA certificate store on Linux, and the Windows certificate store on Windows. In most cases, no extra configuration is needed.</p> |
| <h3>Specifying a CA Certificate File</h3> |
| <p>On some environments, the system CA certificates may not be found. In that case, use <code>set_ca_cert_path()</code> to specify the path directly.</p> |
| <div class="code-block-wrapper"><div data-code-theme="dark"><pre style="background-color:#2b303b;"> |
| <span style="color:#c0c5ce;">httplib::Client </span><span style="color:#8fa1b3;">cli</span><span style="color:#c0c5ce;">("</span><span style="color:#a3be8c;">https://nghttp2.org</span><span style="color:#c0c5ce;">"); |
| </span><span style="color:#c0c5ce;">cli.</span><span style="color:#8fa1b3;">set_ca_cert_path</span><span style="color:#c0c5ce;">("</span><span style="color:#a3be8c;">/etc/ssl/certs/ca-certificates.crt</span><span style="color:#c0c5ce;">"); |
| </span><span style="color:#c0c5ce;"> |
| </span><span style="color:#b48ead;">auto</span><span style="color:#c0c5ce;"> res = cli.</span><span style="color:#8fa1b3;">Get</span><span style="color:#c0c5ce;">("</span><span style="color:#a3be8c;">/</span><span style="color:#c0c5ce;">"); |
| </span></pre> |
| </div><div data-code-theme="light"><pre style="background-color:#ffffff;"> |
| <span style="color:#323232;">httplib::Client </span><span style="font-weight:bold;color:#795da3;">cli</span><span style="color:#323232;">(</span><span style="color:#183691;">"https://nghttp2.org"</span><span style="color:#323232;">); |
| </span><span style="color:#323232;">cli.set_ca_cert_path(</span><span style="color:#183691;">"/etc/ssl/certs/ca-certificates.crt"</span><span style="color:#323232;">); |
| </span><span style="color:#323232;"> |
| </span><span style="font-weight:bold;color:#a71d5d;">auto</span><span style="color:#323232;"> res </span><span style="font-weight:bold;color:#a71d5d;">=</span><span style="color:#323232;"> cli.Get(</span><span style="color:#183691;">"/"</span><span style="color:#323232;">); |
| </span></pre> |
| </div></div><div class="code-block-wrapper"><div data-code-theme="dark"><pre style="background-color:#2b303b;"> |
| <span style="color:#8fa1b3;">curl</span><span style="color:#bf616a;"> --cacert</span><span style="color:#c0c5ce;"> /etc/ssl/certs/ca-certificates.crt https://nghttp2.org/ |
| </span></pre> |
| </div><div data-code-theme="light"><pre style="background-color:#ffffff;"> |
| <span style="color:#323232;">curl --cacert /etc/ssl/certs/ca-certificates.crt https://nghttp2.org/ |
| </span></pre> |
| </div></div> |
| <h3>Disabling Certificate Verification</h3> |
| <p>During development, you might want to connect to a server with a self-signed certificate. You can disable verification for that.</p> |
| <div class="code-block-wrapper"><div data-code-theme="dark"><pre style="background-color:#2b303b;"> |
| <span style="color:#c0c5ce;">httplib::Client </span><span style="color:#8fa1b3;">cli</span><span style="color:#c0c5ce;">("</span><span style="color:#a3be8c;">https://localhost:8443</span><span style="color:#c0c5ce;">"); |
| </span><span style="color:#c0c5ce;">cli.</span><span style="color:#8fa1b3;">enable_server_certificate_verification</span><span style="color:#c0c5ce;">(</span><span style="color:#d08770;">false</span><span style="color:#c0c5ce;">); |
| </span><span style="color:#c0c5ce;"> |
| </span><span style="color:#b48ead;">auto</span><span style="color:#c0c5ce;"> res = cli.</span><span style="color:#8fa1b3;">Get</span><span style="color:#c0c5ce;">("</span><span style="color:#a3be8c;">/</span><span style="color:#c0c5ce;">"); |
| </span></pre> |
| </div><div data-code-theme="light"><pre style="background-color:#ffffff;"> |
| <span style="color:#323232;">httplib::Client </span><span style="font-weight:bold;color:#795da3;">cli</span><span style="color:#323232;">(</span><span style="color:#183691;">"https://localhost:8443"</span><span style="color:#323232;">); |
| </span><span style="color:#323232;">cli.enable_server_certificate_verification(</span><span style="color:#0086b3;">false</span><span style="color:#323232;">); |
| </span><span style="color:#323232;"> |
| </span><span style="font-weight:bold;color:#a71d5d;">auto</span><span style="color:#323232;"> res </span><span style="font-weight:bold;color:#a71d5d;">=</span><span style="color:#323232;"> cli.Get(</span><span style="color:#183691;">"/"</span><span style="color:#323232;">); |
| </span></pre> |
| </div></div><div class="code-block-wrapper"><div data-code-theme="dark"><pre style="background-color:#2b303b;"> |
| <span style="color:#8fa1b3;">curl</span><span style="color:#bf616a;"> -k</span><span style="color:#c0c5ce;"> https://localhost:8443/ |
| </span></pre> |
| </div><div data-code-theme="light"><pre style="background-color:#ffffff;"> |
| <span style="color:#323232;">curl -k https://localhost:8443/ |
| </span></pre> |
| </div></div> |
| <p>Never disable this in production. It opens you up to man-in-the-middle attacks.</p> |
| <h2>Following Redirects</h2> |
| <p>When accessing HTTPS sites, you'll often encounter redirects. For example, <code>http://</code> to <code>https://</code>, or a bare domain to <code>www</code>.</p> |
| <p>By default, redirects are not followed. You can check the redirect target in the <code>Location</code> header.</p> |
| <div class="code-block-wrapper"><div data-code-theme="dark"><pre style="background-color:#2b303b;"> |
| <span style="color:#c0c5ce;">httplib::Client </span><span style="color:#8fa1b3;">cli</span><span style="color:#c0c5ce;">("</span><span style="color:#a3be8c;">https://nghttp2.org</span><span style="color:#c0c5ce;">"); |
| </span><span style="color:#c0c5ce;"> |
| </span><span style="color:#b48ead;">auto</span><span style="color:#c0c5ce;"> res = cli.</span><span style="color:#8fa1b3;">Get</span><span style="color:#c0c5ce;">("</span><span style="color:#a3be8c;">/httpbin/redirect/3</span><span style="color:#c0c5ce;">"); |
| </span><span style="color:#b48ead;">if </span><span style="color:#c0c5ce;">(res) { |
| </span><span style="color:#c0c5ce;"> std::cout << res-></span><span style="color:#bf616a;">status </span><span style="color:#c0c5ce;"><< std::endl; </span><span style="color:#65737e;">// 302 |
| </span><span style="color:#c0c5ce;"> std::cout << res-></span><span style="color:#8fa1b3;">get_header_value</span><span style="color:#c0c5ce;">("</span><span style="color:#a3be8c;">Location</span><span style="color:#c0c5ce;">") << std::endl; |
| </span><span style="color:#c0c5ce;">} |
| </span></pre> |
| </div><div data-code-theme="light"><pre style="background-color:#ffffff;"> |
| <span style="color:#323232;">httplib::Client </span><span style="font-weight:bold;color:#795da3;">cli</span><span style="color:#323232;">(</span><span style="color:#183691;">"https://nghttp2.org"</span><span style="color:#323232;">); |
| </span><span style="color:#323232;"> |
| </span><span style="font-weight:bold;color:#a71d5d;">auto</span><span style="color:#323232;"> res </span><span style="font-weight:bold;color:#a71d5d;">=</span><span style="color:#323232;"> cli.Get(</span><span style="color:#183691;">"/httpbin/redirect/3"</span><span style="color:#323232;">); |
| </span><span style="font-weight:bold;color:#a71d5d;">if </span><span style="color:#323232;">(res) { |
| </span><span style="color:#323232;"> std::cout </span><span style="font-weight:bold;color:#a71d5d;"><<</span><span style="color:#323232;"> res->status </span><span style="font-weight:bold;color:#a71d5d;"><<</span><span style="color:#323232;"> std::endl; </span><span style="font-style:italic;color:#969896;">// 302 |
| </span><span style="color:#323232;"> std::cout </span><span style="font-weight:bold;color:#a71d5d;"><<</span><span style="color:#323232;"> res->get_header_value(</span><span style="color:#183691;">"Location"</span><span style="color:#323232;">) </span><span style="font-weight:bold;color:#a71d5d;"><<</span><span style="color:#323232;"> std::endl; |
| </span><span style="color:#323232;">} |
| </span></pre> |
| </div></div><div class="code-block-wrapper"><div data-code-theme="dark"><pre style="background-color:#2b303b;"> |
| <span style="color:#8fa1b3;">curl</span><span style="color:#c0c5ce;"> https://nghttp2.org/httpbin/redirect/3 |
| </span></pre> |
| </div><div data-code-theme="light"><pre style="background-color:#ffffff;"> |
| <span style="color:#323232;">curl https://nghttp2.org/httpbin/redirect/3 |
| </span></pre> |
| </div></div> |
| <p>Call <code>set_follow_location(true)</code> to automatically follow redirects and get the final response.</p> |
| <div class="code-block-wrapper"><div data-code-theme="dark"><pre style="background-color:#2b303b;"> |
| <span style="color:#c0c5ce;">httplib::Client </span><span style="color:#8fa1b3;">cli</span><span style="color:#c0c5ce;">("</span><span style="color:#a3be8c;">https://nghttp2.org</span><span style="color:#c0c5ce;">"); |
| </span><span style="color:#c0c5ce;">cli.</span><span style="color:#8fa1b3;">set_follow_location</span><span style="color:#c0c5ce;">(</span><span style="color:#d08770;">true</span><span style="color:#c0c5ce;">); |
| </span><span style="color:#c0c5ce;"> |
| </span><span style="color:#b48ead;">auto</span><span style="color:#c0c5ce;"> res = cli.</span><span style="color:#8fa1b3;">Get</span><span style="color:#c0c5ce;">("</span><span style="color:#a3be8c;">/httpbin/redirect/3</span><span style="color:#c0c5ce;">"); |
| </span><span style="color:#b48ead;">if </span><span style="color:#c0c5ce;">(res) { |
| </span><span style="color:#c0c5ce;"> std::cout << res-></span><span style="color:#bf616a;">status </span><span style="color:#c0c5ce;"><< std::endl; </span><span style="color:#65737e;">// 200 (the final response) |
| </span><span style="color:#c0c5ce;">} |
| </span></pre> |
| </div><div data-code-theme="light"><pre style="background-color:#ffffff;"> |
| <span style="color:#323232;">httplib::Client </span><span style="font-weight:bold;color:#795da3;">cli</span><span style="color:#323232;">(</span><span style="color:#183691;">"https://nghttp2.org"</span><span style="color:#323232;">); |
| </span><span style="color:#323232;">cli.set_follow_location(</span><span style="color:#0086b3;">true</span><span style="color:#323232;">); |
| </span><span style="color:#323232;"> |
| </span><span style="font-weight:bold;color:#a71d5d;">auto</span><span style="color:#323232;"> res </span><span style="font-weight:bold;color:#a71d5d;">=</span><span style="color:#323232;"> cli.Get(</span><span style="color:#183691;">"/httpbin/redirect/3"</span><span style="color:#323232;">); |
| </span><span style="font-weight:bold;color:#a71d5d;">if </span><span style="color:#323232;">(res) { |
| </span><span style="color:#323232;"> std::cout </span><span style="font-weight:bold;color:#a71d5d;"><<</span><span style="color:#323232;"> res->status </span><span style="font-weight:bold;color:#a71d5d;"><<</span><span style="color:#323232;"> std::endl; </span><span style="font-style:italic;color:#969896;">// 200 (the final response) |
| </span><span style="color:#323232;">} |
| </span></pre> |
| </div></div><div class="code-block-wrapper"><div data-code-theme="dark"><pre style="background-color:#2b303b;"> |
| <span style="color:#8fa1b3;">curl</span><span style="color:#bf616a;"> -L</span><span style="color:#c0c5ce;"> https://nghttp2.org/httpbin/redirect/3 |
| </span></pre> |
| </div><div data-code-theme="light"><pre style="background-color:#ffffff;"> |
| <span style="color:#323232;">curl -L https://nghttp2.org/httpbin/redirect/3 |
| </span></pre> |
| </div></div> |
| <h2>Next Steps</h2> |
| <p>Now you know how to use the HTTPS client. Next, let's set up your own HTTPS server. We'll start with creating a self-signed certificate.</p> |
| <p><strong>Next:</strong> <a href="../07-https-server">HTTPS Server</a></p> |
| |
| </article> |
| </main> |
| |
| </div> |
| |
| <footer class="footer"> |
| © 2026 Yuji Hirose. All rights reserved. |
| </footer> |
| |
| <!-- Search modal --> |
| <div class="search-overlay" id="search-overlay"> |
| <div class="search-modal"> |
| <div class="search-input-wrap"> |
| <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="11" cy="11" r="8"/><line x1="21" y1="21" x2="16.65" y2="16.65"/></svg> |
| <input type="text" id="search-input" placeholder="Search..." autocomplete="off" spellcheck="false"> |
| <kbd class="search-esc">ESC</kbd> |
| </div> |
| <ul class="search-results" id="search-results"></ul> |
| </div> |
| </div> |
| |
| <script src="/cpp-httplib/js/main.js"></script> |
| </body> |
| </html> |