Skip to content
Raphael Kim edited this page Oct 11, 2016 · 5 revisions

Set Keep connected

  • This function may cause abnormal server response.
    SimpleHTTP http;

    if ( http.keepconnected( true ) == true )
    {
        printf( "HTTP keep connected set.\n" );
    }
    else
    {
        printf( "HTTP keep connected failure.\n" );
    }

    char       url[] = "http://www.google.com";

    http.httpmethod( HTTP_REQ_METHOD_GET );

    if ( http.request( url ) == true )
    {
        printf("[ok.]\n");
    }

    http.closeconnection();

GET a file from HTTP server.

    SimpleHTTP http;
    char       url[] = "http://www.google.com/images/srpr/logo11w.png";

    printf("Requesting for %s ... ", url );

    http.httpmethod( HTTP_REQ_METHOD_GET );
    if ( http.request( url ) == true )
    {
        printf("[ok.]\n");
        FILE* fp = fopen( "google_logo11w.png", "wb" );
        if ( fp != NULL )
        {
             fwrite( http.contents(), 1, http.contentsize(), fp );
             fclose( fp );
        }
    }

POST a some data.

    SimpleHTTP http;
    char       url[] = "http://127.0.0.1/test.php";
    char       posts[] = "test_num=1000; test_string=hahaha";

    printf("Requesting POST for %s ... ", url );

    http.clearcontents();
    http.httpmethod( HTTP_REQ_METHOD_POST );
    http.postcontenttype( SimpleHTTPContentType::APPLICATION | SimpleHTTPContentType::XFORMURLENCODED );
    http.charset( "UTF-8" );
    http.postcontents( posts, strlen( posts ) );
    if ( http.request( url ) == true )
    {
        printf("[ok.]\n");
        if ( http.contentsize() > 0 )
        {
            printf( "%s\n", http.contents() );
        }
    }

Clear Cookie.

    // some work continued ...
    http.resetcookie();
Clone this wiki locally