www.ghoon.net
강지훈 ::
Rss feed
Home
Tag
MediaLog
LocationLog
Guestbook
Admin
Write
Category
분류 전체보기
(14)
Development
(3)
DirectFB
(0)
cURL
(1)
Anything
(1)
Useful Tips
(0)
Notice
Tag
메소드포인터
Total
6,551
Today
10
Y-day
4
티스토리 가입하기
calendar
«
2012/02
»
일
월
화
수
목
금
토
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
Search
Recent Post
Win32 SYSTEMTIME, F...
IPhone Explorer 죽...
Linux shell 용 merg...
VIM에서 현재 Line,...
내 vimrc setting..
Recent Comment
저도 같은 증상...
헐헐
2011
좋은 정보 잘...
꾸로gguro
2010
Recent Trackback
Archive
2011/08
(1)
2011/06
(1)
2011/01
(1)
2010/06
(1)
2010/03
(1)
My Link
fomuon's blog.
hoyeol's blog.
Development/cURL
2008/11/11 10:27
curl URL redirection example
/* * curl_redirection example * * @date 2008.11.10 * @author Kang, Ji-Hoon (kang@ghoon.net) */ #include
#include
#include
typedef struct FtpFile { char filename[FILENAME_MAX]; FILE* stream; } FtpFile; static size_t header_callback(void* ptr, size_t size, size_t nmemb, void* stream) { char* buff = (char*) ptr; const char* content_disposition = "Content-Disposition: attachment;" "filename="; if (strstr(buff, content_disposition)) { FtpFile* pFileInfo = (FtpFile*) stream; memset(pFileInfo->filename, 0, sizeof(pFileInfo->filename)); memcpy(pFileInfo->filename, buff+strlen(content_disposition), strlen(buff) - strlen(content_disposition) - 2); printf("catched filename : %s length : %d\n", pFileInfo->filename, strlen(pFileInfo->filename)); } return size * nmemb; } static size_t write_callback(void* buffer, size_t size, size_t nmemb, void* stream) { FtpFile* out = (FtpFile*) stream; if ((out && !out->stream) && out->filename) { out->stream = fopen(out->filename, "wb"); if (!out->stream) { return -1; } } return fwrite(buffer, size, nmemb, out->stream); } /** * @param [in] hCurl - curl handle * @param [in] sURL - * @param [in] sLocalDir - * @return 'CURLE_OK' ok, otherwise failure. */ static CURLcode download(CURL* hCurl, const char* sURL, const char* sLocalDir) { FtpFile localfile; memset(&localfile, 0, sizeof(FtpFile)); curl_easy_setopt(hCurl, CURLOPT_HEADERFUNCTION, header_callback); curl_easy_setopt(hCurl, CURLOPT_HEADERDATA, &localfile); curl_easy_setopt(hCurl, CURLOPT_URL, sURL); curl_easy_setopt(hCurl, CURLOPT_WRITEFUNCTION, write_callback); curl_easy_setopt(hCurl, CURLOPT_WRITEDATA, &localfile); curl_easy_setopt(hCurl, CURLOPT_VERBOSE, 1); CURLcode res = curl_easy_perform(hCurl); if (localfile.stream) { fclose(localfile.stream); } return res; } int main(int argc, char** argv) { const char* sURL = "http://fmov.pann.com/mmediaDownload.jsp?" "FileID=12992569"; const char* sLocalDir = "/home/david/Download"; CURL* hCurl = NULL; curl_global_init(CURL_GLOBAL_ALL); hCurl = curl_easy_init(); download(hCurl, sURL, sLocalDir); curl_easy_cleanup(hCurl); curl_global_cleanup(); return 0; }
posted by
강지훈
Trackback
0
:
Comment
0
Trackback :
http://www.ghoon.net/trackback/10
<
PREV
NEXT
>
1
...
7
8
9
10
11
12
13
14