使用HTTPS发送POST参数

Sending POST parameters using HTTPS

本文关键字:参数 POST 发送 HTTPS 使用      更新时间:2024-04-28

config.h文件

#define HOST_NAME "test.com"
#define HOST_PORT 5000
cpr::Response r = cpr::Post(cpr::Url{std::string("https://" + HOST_NAME + ":" + std::to_string(HOST_PORT) + "/setup")}, cpr::Parameters{{"c", computername}, {"u", username}, {"p", hashedPassword}});

错误:

表达式必须具有整型或非量程枚举类型

"+"无法添加两个指针

"https://" + HOST_NAME + ":"

此部分扩展到

"https://" + "test.com" + ":"

不能直接添加两个字符串文字。

您可以通过简单地编写字符串文字来连接它们,而无需添加以下运算符:

"https://" HOST_NAME ":"

另一种方法是将std::string用于添加的内容之一:

"https://" + std::string(HOST_NAME) + ":"