#include <stdio.h>
#include <string.h>
#include <curl/curl.h>
int main(void)
{
CURL *curl;
CURLcode res;
static const char *postthis="test";
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "http://www.groad.net/index.html");
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, postthis);
/* 如果我们不提供 POSTFIELDSIZE, libcurl 自己会 strlen() */
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)strlen(postthis));
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
return 0;
}
编译连接:
`curl-config --cc --cflags --libs` -o post post.c
L$ ./post
[Plain Text] 纯文本查看 复制代码<html>
<head><title>405 Not Allowed</title></head>
<body bgcolor="white">
<center><h1>405 Not Allowed</h1></center>
<hr><center>nginx/0.6.37</center>
</body>
</html>
$ curl -d test http://www.groad.net/index.html
<html>
<head><title>405 Not Allowed</title></head>
<body bgcolor="white">
<center><h1>405 Not Allowed</h1></center>
<hr><center>nginx/0.6.37</center>
</body>
</html>
欢迎光临 曲径通幽论坛 (http://www.groad.net/bbs/) | Powered by Discuz! X3.2 |