C++ REST SDK i
Welcome!
The C++ REST SDK is a Microsoft project for cloud-based client-server communication in native code using a modern asynchronous C++ API design. This project aims to help C++ developers connect to and interact with services.
Getting Started
With vcpkg on Windows
PS> vcpkg install cpprestsdk cpprestsdk:x64-windows
With apt-get on Debian/Ubuntu
$ sudo apt-get install libcpprest-dev
With brew on OSX
$ brew install cpprestsdk
With NuGet on Windows for Android
PM> Install-Package cpprestsdk.android
For other platforms, install options, how to build from source, and more, take a look at our Documentation.
Once you have the library, look at our tutorial to use the http_client. It walks through how to setup a project to use the C++ Rest SDK and make a basic Http request.
To use from CMake:
cmake_minimum_required(VERSION 3.7)
project(main) find_package(cpprestsdk REQUIRED) add_executable(main main.cpp)
target_link_libraries(main PRIVATE cpprestsdk::cpprest)
What's in the SDK:
- Features - HTTP client/server, JSON, URI, asynchronous streams, WebSockets client, oAuth
- PPL Tasks - A powerful model for composing asynchronous operations based on C++ 11 features
- Platforms - Windows desktop, Windows Store (UWP), Linux, OS X, Unix, iOS, and Android
- Support for Visual Studio 2015 and 2017 with debugger visualizers
Contribute Back!
Is there a feature missing that you'd like to see, or found a bug that you have a fix for? Or do you have an idea or just interest in helping out in building the library? Let us know and we'd love to work with you. For a good starting point on where we are headed and feature ideas, take a look at our requested features and bugs.
Big or small we'd like to take your contributions back to help improve the C++ Rest SDK for everyone. If interested contact us askcasablanca at Microsoft dot com.
Having Trouble?
We'd love to get your review score, whether good or bad, but even more than that, we want to fix your problem. If you submit your issue as a Review, we won't be able to respond to your problem and ask any follow-up questions that may be necessary. The most efficient way to do that is to open a an issue in our issue tracker.
Quick Links
- FAQ
- Documentation
- Issue Tracker
- Directly contact us: askcasablanca@microsoft.com
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.
安装微软的开源 cpprestsdk (C++ REST SDK (codename "Casablanca")),要先有项目;这里新建一个WIN32控制台项目,名为XXX,默认使用系统生成的代码;
然后打开:VS2013 -> 工具 ->库程序包管理器->程序包管理器控制台
输入 :
install-package cpprestsdk
等待安装完毕;
或者慢的话,到 https://www.nuget.org/packages?q=cpprestsdk.v120
手动把这几个包下载下来(点击进去,点download)放到缓存目录: C:\Users\Administrator\AppData\Local\NuGet\Cache
再执行 install-package cpprestsdk
等待安装
显示
。。。
已成功将“cpprestsdk 2.9.1.1”添加到 xxx (你新建的项目名),则安装成功。
把main文件所在的代码替换成下面例子的代码:
- // xx.cpp : 定义控制台应用程序的入口点。
- //
- #include "stdafx.h"
- /*
- int _tmain(int argc, _TCHAR* argv[])
- {
- return 0;
- }
- */
- #include <cpprest/http_client.h>
- #include <cpprest/json.h>
- //#include <http_client.h>
- #include <iostream>
- //#include <json.h>
- using namespace web;
- using namespace web::http;
- using namespace web::http::client;
- using namespace std;
- // Retrieves a JSON value from an HTTP request.
- pplx::task<void> RequestJSONValueAsync()
- {
- // TODO: To successfully use this example, you must perform the request
- // against a server that provides JSON data.
- // This example fails because the returned Content-Type is text/html and not application/json.
- //http_client client(L"http://www.fourthcoffee.com");
- http_client client(L"http://www.fourthcoffee.com");
- return client.request(methods::GET).then([](http_response response) -> pplx::task<json::value>
- {
- if (response.status_code() == status_codes::OK)
- {
- wcout<< response.extract_string().get().c_str()<<endl;
- return response.extract_json();
- }
- // Handle error cases, for now return empty json value...
- return pplx::task_from_result(json::value());
- })
- .then([](pplx::task<json::value> previousTask)
- {
- try
- {
- const json::value& v = previousTask.get();
- // Perform actions here to process the JSON value...
- }
- catch (const http_exception& e)
- {
- // Print error.
- wostringstream ss;
- ss << e.what() << endl;
- wcout << ss.str();
- }
- });
- /* Output:
- Content-Type must be application/json to extract (is: text/html)
- */
- }
- // Demonstrates how to iterate over a JSON object.
- void IterateJSONValue()
- {
- // Create a JSON object.
- json::value obj;
- obj[L"key1"] = json::value::boolean(false);
- obj[L"key2"] = json::value::number(44);
- obj[L"key3"] = json::value::number(43.6);
- obj[L"key4"] = json::value::string(U("str"));
- // Loop over each element in the object.
- for (auto iter = obj.as_object().cbegin(); iter != obj.as_object().cend(); ++iter)
- {
- // Make sure to get the value as const reference otherwise you will end up copying
- // the whole JSON value recursively which can be expensive if it is a nested object.
- //const json::value &str = iter->first;
- //const json::value &v = iter->second;
- const auto &str = iter->first;
- const auto &v = iter->second;
- // Perform actions here to process each string and value in the JSON object...
- std::wcout << L"String: " << str.c_str() << L", Value: " << v.serialize() << endl;
- }
- /* Output:
- String: key1, Value: false
- String: key2, Value: 44
- String: key3, Value: 43.6
- String: key4, Value: str
- */
- }
- int wmain()
- {
- // This example uses the task::wait method to ensure that async operations complete before the app exits.
- // In most apps, you typically don�t wait for async operations to complete.
- wcout << L"Calling RequestJSONValueAsync..." << endl;
- RequestJSONValueAsync().wait();
- wcout << L"Calling IterateJSONValue..." << endl;
- IterateJSONValue();
- getchar();
- }
编译,运行,结果:
.............
d)/*]]>*/</script></body></html>
Calling IterateJSONValue...
String: key1, Value: false
String: key2, Value: 44
String: key3, Value: 43.600000000000001
String: key4, Value: "str"
C++ REST SDK i的更多相关文章
- 配置android sdk 环境
1:下载adnroid sdk安装包 官方下载地址无法打开,没有vpn,使用下面这个地址下载,地址:http://www.android-studio.org/
- 阿里云直播 C# SDK 如何使用
阿里云直播SDK的坑 1.直播云没有单独的SDK,直播部分被封装在CDN的相关SDK当中. 2.针对SDK,没有相关Demo. 3.针对SDK,没有相关的文档说明. 4.针对SDK的说明,官网上的说明 ...
- 使用Visual Studio SDK制作GLSL词法着色插件
使用Visual Studio SDK制作GLSL词法着色插件 我们在Visual Studio上开发OpenGL ES项目时,避免不了写Shader.这时在vs里直接编辑shader就会显得很方便. ...
- iOS开发之App间账号共享与SDK封装
上篇博客<iOS逆向工程之KeyChain与Snoop-it>中已经提到了,App间的数据共享可以使用KeyChian来实现.本篇博客就实战一下呢.开门见山,本篇博客会封装一个登录用的SD ...
- Intel Media SDK H264 encoder GOP setting
1 I帧,P帧,B帧,IDR帧,NAL单元 I frame:帧内编码帧,又称intra picture,I 帧通常是每个 GOP(MPEG 所使用的一种视频压缩技术)的第一个帧,经过适度地压缩,做为随 ...
- Android SDK 在线更新镜像服务器资源
本文转自:http://blog.kuoruan.com/24.html.感谢原作者. 什么是Android SDK SDK:(software development kit)软件开发工具包.被软件 ...
- TYPESDK手游聚合SDK服务端设计思路与架构之二:服务端设计
在前一篇文中,我们对一个聚合SDK服务端所需要实现的功能作了简单的分析.通过两个主要场景的功能流程图,我们可以看到,作为多款游戏要适配多个渠道的统一请求转发中心,TYPESDK服务端主要需要实现的功能 ...
- TYPESDK手游聚合SDK服务端设计思路与架构之一:应用场景分析
TYPESDK 服务端设计思路与架构之一:应用场景分析 作为一个渠道SDK统一接入框架,TYPESDK从一开始,所面对的需求场景就是多款游戏,通过一个统一的SDK服务端,能够同时接入几十个甚至几百个各 ...
- Android SDK 与API版本对应关系
Android SDK版本号 与 API Level 对应关系如下表: Code name Version API level (no code name) 1.0 API level 1 ( ...
- Kotlin与Android SDK 集成(KAD 05)
作者:Antonio Leiva 时间:Dec 19, 2016 原文链接:https://antonioleiva.com/kotlin-integrations-android-sdk/ 使用Ko ...
随机推荐
- [Go] 反射 - reflect.ValueOf()
类型 和 接口 由于反射是基于类型系统(type system)的,所以先简单了解一下类型系统. 首先 Golang 是一种静态类型的语言,在编译时每一个变量都有一个类型对应,例如:int, floa ...
- VisualStudio:让 XML 支持智能提示
将 XSD 文件拷贝到 VS 下的指定目录,我的电脑上的目录为:C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\Packages ...
- 为网卡配置多个IP地址(windows)
转自:https://jingyan.baidu.com/article/fcb5aff7e0fd76edaa4a71d3.html 为电脑配置多个IP,免去到不同地点需要更改IP的烦恼. 譬如电脑在 ...
- 星际之门SG1第一至十季/全集Stargate SG-1迅雷下载
英文译名 Stargate SG-1 (第一至十季) (1997-2008)Syfy.本季看点:<星际之门 SG-1>1997年起在美播出第一季,并于全球30多个国家播映,反应热烈,今年( ...
- iTunes Connect开发者指南中的一个疑问
iTunes Connect Developer Guide 避免app版本出现在iClound中,我的疑问是对已经上架的版本不能设置,那么这个功能的真正意义在哪里? 大部分用户去应用页面下载 ...
- hihocoder #1170 机器人 && 编程之美2015复赛
题意: 时间限制:2000ms 单点时限:1000ms 内存限制:256MB 描写叙述 小冰的N个机器人兄弟排成一列,每一个机器人有一个颜色. 如今小冰想让同一颜色的机器人聚在一起.即随意两个同颜色的 ...
- [Network] okhttp3与旧版本okhttp的区别分析
cp from : https://www.jianshu.com/p/4a8c94b239b4 1.包名改变 包名改了由之前的 com.squareup.http.改为 okhttp3. 我们需要将 ...
- 启明星手机版安卓android会议室预定系统 V1.0发布
启明星手机版会议室预定系统 V1.0发布 在手机里输入 http://www.dotnetcms.org/e4.apk 或者扫描二维码下载 用户打开系统,可以实时查看所有会议室状态 点击会议室名称,可 ...
- ab命令作apache压力测试
ab命令作apache压力测试 ./ab -c 100 -n 10000 http://127.0.0.1/index.php -c 100 即:每次并发100个 -n 10000 即: 共发送100 ...
- asp.net mvc Controller控制器返回类型
ASP.NET MVC包括了执行常见任务的ActionResult类型.这些类型罗列在表5-1中.每个类型都将在随后的小节中详细讨论. 表5-1 动作结果的类型及其说明 动作结果的类型 说 明 ...