File: verify_none.cpp

package info (click to toggle)
restbed 4.0~dfsg1-5
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,388 kB
  • sloc: cpp: 15,273; sh: 37; makefile: 14
file content (51 lines) | stat: -rw-r--r-- 1,521 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*
 * Example illustrating a HTTPS client with no peer verification.
 *
 * Usage:
 *    ./distribution/example/https_client_verify_none
 */

#include <memory>
#include <cstdio>
#include <cstdlib>
#include <restbed>

using namespace std;
using namespace restbed;

int main( const int, const char** )
{
    auto request = make_shared< Request >( Uri( "https://www.google.co.nz/" ) );
    request->set_header( "Accept", "*/*" );
    request->set_header( "Host", "www.google.co.nz" );
    request->set_query_parameter( "query", "search term" );
    
    auto response = Http::sync( request );
    
    fprintf( stderr, "*** Response ***\n" );
    fprintf( stderr, "Status Code:    %i\n", response->get_status_code( ) );
    fprintf( stderr, "Status Message: %s\n", response->get_status_message( ).data( ) );
    fprintf( stderr, "HTTP Version:   %.1f\n", response->get_version( ) );
    fprintf( stderr, "HTTP Protocol:  %s\n", response->get_protocol( ).data( ) );
    
    for ( const auto header : response->get_headers( ) )
    {
        fprintf( stderr, "Header '%s' > '%s'\n", header.first.data( ), header.second.data( ) );
    }
    
    if ( response->has_header( "Transfer-Encoding" ) )
    {
        Http::fetch( "\r\n", response );
    }
    else
    {
        auto length = 0;
        response->get_header( "Content-Length", length );
        
        Http::fetch( length, response );
    }
    
    fprintf( stderr, "Body:           %.*s...\n", 3, response->get_body( ).data( ) );
    
    return EXIT_SUCCESS;
}