c语言curl post请求
时间: 2023-11-04 12:00:38 浏览: 70
您可以使用C语言中的libcurl库来进行POST请求。以下是一个简单的示例代码:
```c
#include <stdio.h>
#include <curl/curl.h>
int main(void)
{
CURL *curl;
CURLcode res;
// 初始化curl
curl_global_init(CURL_GLOBAL_DEFAULT);
// 创建一个curl句柄
curl = curl_easy_init();
if(curl) {
// 设置请求的URL
curl_easy_setopt(curl, CURLOPT_URL, "http://www.example.com");
// 设置POST请求
curl_easy_setopt(curl, CURLOPT_POST, 1L);
// 设置POST数据
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "key1=value1&key2=value2");
// 发送请求
res = curl_easy_perform(curl);
if(res != CURLE_OK)
fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
// 清理curl
curl_easy_cleanup(curl);
}
// 清理全局curl状态
curl_global_cleanup();
return 0;
}
```
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)