什么是最有效的方式来获得网页源$ C $ C用C? [英] What's the most efficient way to get source code of web page in C?
本文介绍了什么是最有效的方式来获得网页源$ C $ C用C?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 PHP 我能做到这一点就这么简单:
的file_get_contents('http://stackoverflow.com/questions/ask');
什么是最短code做同样的 C
更新
当我编译的卷曲样品,得到了这样的错误:
在函数_main引用解析的外部符号__imp__curl_easy_cleanup
解决方案
使用 libcurl的,指他们的< A HREF =http://curl.haxx.se/libcurl/c/example.html相对=nofollow>例如,C片段
的#include&LT;&stdio.h中GT;
#包括LT&;卷曲/ curl.h&GT;INT主要(无效)
{
卷曲*卷曲;
卷曲code资源; 卷曲= curl_easy_init();
如果(卷曲){
curl_easy_setopt(卷曲,CURLOPT_URL,curl.haxx.se);
RES = curl_easy_perform(卷曲); / *总是清理* /
curl_easy_cleanup(卷曲);
}
返回0;
}
In PHP I can do it as simple as :
file_get_contents('http://stackoverflow.com/questions/ask');
What's the shortest code to do the same in C?
UPDATE
When I compile the sample with curl, got errors like this:
unresolved external symbol __imp__curl_easy_cleanup referenced in function _main
解决方案
Use libcurl, refer to their example C snippets
#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, "curl.haxx.se");
res = curl_easy_perform(curl);
/* always cleanup */
curl_easy_cleanup(curl);
}
return 0;
}
这篇关于什么是最有效的方式来获得网页源$ C $ C用C?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文