CppRequests 0.0.2
See the version list below for details.
dotnet add package CppRequests --version 0.0.2
NuGet\Install-Package CppRequests -Version 0.0.2
<PackageReference Include="CppRequests" Version="0.0.2" />
paket add CppRequests --version 0.0.2
#r "nuget: CppRequests, 0.0.2"
// Install CppRequests as a Cake Addin #addin nuget:?package=CppRequests&version=0.0.2 // Install CppRequests as a Cake Tool #tool nuget:?package=CppRequests&version=0.0.2
Visual Stdio设置(Setting):
添加静态链接库路径(Add Static Lib Path):项目属性->链接器(Linker)->常规(Normal)->附加库目录(Additional library directory):
YourProjectRootPath\packages\CppRequests.0.0.2\build\native\lib\Win32\v120\static\Debug (if you are win32/debug project setting)
YourProjectRootPath\packages\CppRequests.0.0.2\build\native\lib\Win32\v120\static\Release (if you are win32/release project setting)
YourProjectRootPath\packages\CppRequests.0.0.2\build\native\lib\x64\v120\static\Debug (if you are x64/debug project setting)
YourProjectRootPath\packages\CppRequests.0.0.2\build\native\lib\x64\v120\static\Release (if you are x64/release project setting)
添加静态库依赖(AdditionalDependencies):项目属性->链接器(Linker)->输入(Input)->附加库依赖项(AdditionalDependencies): HttpLib.lib
目前实现的http动作有(The currently implemented http action):GET POST HEAD OPTIONS PUT DELETE
入门(Get Started)
#include <iostream>
#include <string>
#include "requests.h"
using namespace std;
using namespace requests;
int main(int argc)
{
Response resp = Get("https://baidu.com");
cout << resp.status << endl;
cout << resp.GetText() << endl;
return 0;
}
Get获取网页内容(Use Get)
Response resp = Get("https://pan.baidu.com/disk/home");
cout << resp.GetText() << endl; `
Post请求使用,上传json数据(Post with Json)
map<string, string> data;
data["name"] = "cpp";
data["age"] = "14";
Response resp = Post("http://47.106.162.182:8080/post.php", data);
cout << resp.status << endl;
cout << resp.GetText() << endl;
Put上传文件(Use Put)
Response resp = Put("http://httpbin.org/put", "C:\\Users\\jack\\Desktop\\key.txt");
cout << resp.status << endl;
cout << resp.GetText() << endl;
Get带cookie访问网页(Get With Cookie)
map<string, string> header;
string cookie = "BAIDUID=B066E871294A61BE394DE24FFA475653:FG=1; BIDUPSID=B066E871294A61BE9EF72E101F79BF87; PSTM=1578882286;";
Response resp = Get("https://pan.baidu.com/disk/home",header,cookie);
cout << resp.GetText() << endl;
设置代理(Config Http Proxy)
map<string, string> options;
map<string, string> header;
options["proxy"] = "http=http://122.51.49.88:8888";
try{
Response resp = Get("http://pv.sohu.com/cityjson",header , "", options);
cout << resp.status << endl;
}
catch (const char *msg){
cout << msg << endl;
}
自定义Http Header(customize Http Header)
map<string, string> header;
map<string, string> options;
options["timeout"] = "5000";
header["name"] = "cpp";
header["age"] = "14"; header["User-Agent"] = "Cpp Brower"
Response resp = Get("http://httpbin.org/headers",header);
cout << resp.status << endl;
cout << resp.GetText() << endl;
上传文件(Upload File)
map<string, string> header;
map<string, string> data;
map<string, string> files;
data["key"] = "something";
data["submit"] = "Submit"; //form表单的其他要上传的数据,如账号密码。
files["file"] = "C:\stdafx.h"; //form表单中的文件字段。
Response resp = Post(url,data,files);
cout << resp.status << endl;
cout << resp.GetText() << endl;
Product | Versions Compatible and additional computed target framework versions. |
---|---|
native | native is compatible. |
This package has no dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Release of Requests 0.0.1 libraries.