Network programming using the C + + REST SDK

Source: Internet
Author: User

Installing the C + + REST SDK
$ brew install cpprestsdk$ brew install boost$ brew install libressl
Create a project

Open Xcode,file/new/project ...
On page 1th of the wizard, select Macos/command line Tool
On the 2nd page of the wizard, select C++,product name to fill in any name
on page 3rd of the wizard, select any folder and click Create to build the project.

Configuration Engineering

Set the System Header Search Paths to
/usr/local/cellar/cpprestsdk/2.10.2/include
/usr/local/cellar/boost/1.67.0_1/include
/usr/local/cellar/libressl/2.7.4/include

Set the Library Search Paths to
/usr/local/cellar/cpprestsdk/2.10.2/lib
/usr/local/cellar/boost/1.67.0_1/lib
/usr/local/cellar/libressl/2.7.4/lib

Set the other Linker Flags to
-lcpprest-lboost_system-lboost_thread-mt-lboost_chrono-mt-lssl-lcrypto

cpprestsdk:undefined Symbols for Architecture x86_64

C + + code
#include <cpprest/http_client.h> #include <cpprest/filestream.h>using namespace utility;                        Common utilities like string conversionsusing namespace web;                  Common features like uris.using namespace Web::http;          Common HTTP functionalityusing namespace web::http::client;       HTTP client featuresusing namespace Concurrency::streams;    Asynchronous Streamsint Main (int argc, char* argv[]) {Auto FileStream = std::make_shared<ostream> ();    Open stream to output file. pplx::task<void> requesttask = Fstream::open_ostream (U ("results.html")). then ([=] (Ostream outFile) {*files        Tream = OutFile;        Create http_client to send the request.        Http_client Client (U ("http://www.bing.com/"));        Build request URI and start the request.        Uri_builder Builder (U ("/search"));        Builder.append_query (U ("Q"), U ("cpprestsdk GitHub")); Return Client.request (methodS::get, builder.to_string ());    })//Handle response headers arriving.        . then ([=] (http_response response) {printf ("Received response status code:%u\n", Response.status_code ());        Write response body into the file.    Return Response.body (). Read_to_end (Filestream->streambuf ());    })//Close the file stream.    . then ([=] (size_t) {return filestream->close ();    });    Wait for all the outstanding I/O and handle any exceptions try {requesttask.wait ();    } catch (const std::exception &e) {printf ("Error exception:%s\n", E.what ()); } return 0;}

Network programming using the C + + REST SDK

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.