|
程序代码:
#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, "www.groad.net");
res = curl_easy_perform (curl);
curl_easy_cleanup(curl);
}
return (0);
} 编译链接与生成:$ `curl-config --cc --cflags --libs` -o simple simple.c
运行与输出:$ ./simple
<html>
<head>
<meta name="verify-v1" content="Saip2MsYYjGl+/cQmLCqtX5ahZclw2b4s2pPJ/ot/9Q=" />
<meta http-equiv="refresh" content="0;url=http://www.groad.net/bbs/index.php">
<title>Welcome To Groad.Net</title>
</head>
</html> 从上面可以看到,我的论坛空间是用了一个 *.html 做了首页跳转的。
程序说明:
一开始调用了 curl_easy_init() 函数进行了初始化。如果成功初始化,则调用 curl_easy_setopt() 来设置一个需要访问的 URL ,最后使用 curl_easy_cleanup() 函数来结束这次的 CR 会话。 |
|