在保存下使用libcurl的文件 [英] Saving a file using libcurl in C
本文介绍了在保存下使用libcurl的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在Perl到C扩大,我试图用卷曲的图书馆简单地从远程URL保存一个文件,但我有一个很难找到一个很好的例子,从工作。
I'm expanding from perl to C and I'm trying to use curl's library to simply save a file from a remote url but I'm having a hard time finding a good example to work from.
另外,我不知道我是否应该使用curl_easy_recv或curl_easy_perform
Also, I'm not sure if I should be using curl_easy_recv or curl_easy_perform
推荐答案
我觉得这种资源非常的开发商友好。
我编译源$ C $ C如下:
I compiled the source code below with:
gcc demo.c -o demo -I/usr/local/include -L/usr/local/lib -lcurl
基本上,它会下载一个文件,并将其保存在硬盘上。
Basically, it will download a file and save it on your hard disk.
文件 demo.c
#include <curl/curl.h>
#include <stdio.h>
void get_page(const char* url, const char* file_name)
{
CURL* easyhandle = curl_easy_init();
curl_easy_setopt( easyhandle, CURLOPT_URL, url ) ;
FILE* file = fopen( file_name, "w");
curl_easy_setopt( easyhandle, CURLOPT_WRITEDATA, file) ;
curl_easy_perform( easyhandle );
curl_easy_cleanup( easyhandle );
fclose(file);
}
int main()
{
get_page( "http://blog.stackoverflow.com/wp-content/themes/zimpleza/style.css", "style.css" ) ;
return 0;
}
另外,我相信你的问题是类似这样的:
Also, I believe your question is similar to this one:
这篇关于在保存下使用libcurl的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文