现在有个项目需要把本地数据库中指定的数据上传到服务器,现在云服务器提供了RestAPI接口,我在VC中如何调用和使用RestAPI.
1.rest不就是json+http嘛,http支持MFC有,找个json库就行
2.微软的cpprestsdk
https://github.com/microsoft/cpprestsdk
Environment
OS: Windows 10.0.18362, VS 2019, clean new environment.
Compiler: revision
Microsoft Visual Studio Enterprise 2019 Version 16.4.2
Visual Studio 2019 c++ Libraries like RestSDK for C++
step 1: add the REST SDK to a project by using NuGet.
Install packages with VCPKG (C++包管理工具)
open command window as admin and enter
Vcpkg helps you manage C and C++ libraries on Windows, Linux, and macOS.
vcpkg作为微软开发的一款C++开源代码管理工具,并未随Visual Studio 安装在系统中,需要手动下载该工具源码并进行编译才可以使用.
该工具除了可以下载Cpp Rest SDK源码外还可自动下载相关依赖包,并通过命令行进行自动编译、向VisualStudio引入相关库,大大简化了在自己的项目中使用Cpp Rest SDK的难度。
Vcpkg自动下载源码然后编译成三方库,而且并不依赖于Windows注册表或Visual Studio.
step 1:Clone the VCPKG repo from GitHub
step 2:compile the package manager(运行完成后,会在当前目录下生成vcpkg.exe)
output
step 3:install the C++ REST SDK on windows
C++ REST SDK can be installed on Windows by using VCPKG
三方库的下载和编译命令是vcpkg install
output
other:
run failure because of language pack in vs2019
在Visual Studio Installer中“修改”,点击“语言包”,勾上英语
We can check that cpprestsdk was successfully installed for x86 Windows desktop by running the list command.
PS D:\src\vcpkg> .\vcpkg list
step 4:vcpkg integration in Visual Studio 2019 for CMake projects(整合Vcpkg sdk到VS中)
The recommended and most productive way to use vcpkg is via user-wide integration, making the system available for all projects you build. The user-wide integration will prompt for administrator access the first time it is used on a given machine, but afterwards is no longer required and the integration is configured on a per-user basis.
vcpkg integrate install命令将所有三方库的头文件和二进制文件自动配置到Visual Studio中
For usage in Visual Studio you have to enable the system wide integration with
Note: You will need to restart Visual Studio or perform a Build to update intellisense with the changes.
other
step 5: include a C++ REST SDK header into your Visual Studio C++ project
install C++ REST SDK using nuget
https://social.msdn.microsoft.com/Forums/vstudio/en-US/1b7d3e81-85e5-4ec0-bd60-f424dceab232/visual-studio-2019-libraries-like-restsdk-for-c
build CppRestSDK using Vcpkg
How to build CppRestSDK using Vcpkg in Visual Studio 2019 (X64 windows & X86 windows)
http://cool-emerald.blogspot.com/2020/10/c-rest-sdk.html
https://sageai.blogspot.com/2020/12/how-to-build-cpprestsdk-using-vcpkg-in.html
https://vcpkg.readthedocs.io/en/latest/examples/installing-and-using-packages/
https://blog.csdn.net/Lasuerte/article/details/86689703(ok cn)
code
Full-fledged client-server example with C++ REST SDK 2.10