CURLOPT_CUSTOMREQUEST
时间: 2024-04-26 19:19:35 浏览: 9
CURLOPT_CUSTOMREQUEST是libcurl库中的一个选项,用于设置HTTP请求的自定义方法。它允许您将HTTP请求方法设置为除了GET和POST之外的其他方法,例如PUT、DELETE等。您可以使用curl_easy_setopt函数来设置CURLOPT_CUSTOMREQUEST选项。
以下是一个示例,演示如何使用CURLOPT_CUSTOMREQUEST将HTTP请求方法设置为PUT:
```c
#include <stdio.h>
#include <curl/curl.h>
int main(void) {
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "http://example.com");
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "PUT");
res = curl_easy_perform(curl);
if(res != CURLE_OK)
fprintf(stderr, "curl_easy_perform() failed: %s\n",
curl_easy_strerror(res));
curl_easy_cleanup(curl);
}
return 0;
}
```
在上述示例中,我们使用curl_easy_setopt函数将CURLOPT_CUSTOMREQUEST选项设置为"PUT",以将HTTP请求方法设置为PUT。然后,我们使用curl_easy_perform函数执行HTTP请求。