C++ 通过curl请求TSP身份证书代码
时间: 2024-03-21 12:14:43 浏览: 172
以下是使用C++和Curl库发送HTTP请求获取TSP身份证书的示例代码:
```cpp
#include <iostream>
#include <curl/curl.h>
int main() {
CURL *curl;
CURLcode res;
std::string url = "https://tsp.iaik.tugraz.at/tsp/TspRequest";
// Initialize curl
curl = curl_easy_init();
if (curl) {
// Set URL
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
// Set request method to POST
curl_easy_setopt(curl, CURLOPT_POST, 1L);
// Set request body
std::string requestBody = "message="; // Replace with your message
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, requestBody.c_str());
// Send request and get response
res = curl_easy_perform(curl);
// Check for errors
if (res != CURLE_OK) {
std::cerr << "curl_easy_perform() failed: " << curl_easy_strerror(res) << std::endl;
}
// Cleanup
curl_easy_cleanup(curl);
} else {
std::cerr << "Failed to initialize curl" << std::endl;
}
return 0;
}
```
注意,这只是一个基本示例,你需要根据自己的具体情况修改URL、请求方法、请求体等参数。另外,你需要在编译时链接Curl库。
阅读全文