1#include<stdio.h>2#include<string.h>3#include<curl/curl.h>45#defineMAX_BUF65536067char wr_buf[MAX_BUF+1];//Buffer for Body8int wr_index;//write index for Body910char wr_buf2[MAX_BUF+1];//buffer for Header11int wr_index2;//write index for Header121314size_twrite_header(void*buffer,size_t size,size_t nmemb,void*userp)15{1617int segsize = size * nmemb;1819/* Check to see if this data exceeds the size of our buffer. If so,
20 * set the user-defined context value and return 0 to indicate a
21 * problem to curl.
22 */23if( wr_index2 + segsize > MAX_BUF ){24*(int*)userp =1;25return0;26}2728/* Copy the data from the curl buffer into our buffer */29memcpy((void*)&wr_buf2[wr_index2], buffer,(size_t)segsize );3031/* Update the write index */32 wr_index2 += segsize;3334/* Null terminate the buffer */35 wr_buf2[wr_index2]=0;3637/* Return the number of bytes received, indicating to curl that all is okay */38return segsize;3940}41424344/*
45 * Write data callback function (called within the context of
46 * curl_easy_perform.
47 */48size_twrite_data(void*buffer,size_t size,size_t nmemb,void*userp )49{50int segsize = size * nmemb;5152/* Check to see if this data exceeds the size of our buffer. If so,
53 * set the user-defined context value and return 0 to indicate a
54 * problem to curl.
55 */56if( wr_index + segsize > MAX_BUF ){57*(int*)userp =1;58return0;59}6061/* Copy the data from the curl buffer into our buffer */62memcpy((void*)&wr_buf[wr_index], buffer,(size_t)segsize );6364/* Update the write index */65 wr_index += segsize;6667/* Null terminate the buffer */68 wr_buf[wr_index]=0;6970/* Return the number of bytes received, indicating to curl that all is okay */71return segsize;72}737475/*
76 * Simple curl application to read the index.html file from a Web site.
77 */78intmain(void)79{80 CURL *curl;81 CURLcode ret;82int wr_error;8384 wr_error =0;85 wr_index =0;8687/* First step, init curl */88 curl =curl_easy_init();89if(!curl){90printf("couldn't init curl\n");91return0;92}9394/* Tell curl the URL of the file we're going to retrieve */95curl_easy_setopt( curl, CURLOPT_URL,"http://yokotatsu.webcrow.jp");96curl_easy_setopt( curl, CURLOPT_WRITEDATA,(void*)&wr_error );97curl_easy_setopt( curl, CURLOPT_HEADER,0L);98curl_easy_setopt( curl, CURLOPT_HEADERFUNCTION, write_header );99curl_easy_setopt( curl, CURLOPT_WRITEFUNCTION, write_data );100101/* Allow curl to perform the action */102 ret =curl_easy_perform( curl );103104printf("ret = %d (write_error = %d)\n", ret, wr_error );105106/* Emit the page if curl indicates that no errors occurred */107if( ret ==0){108printf("%s\n", wr_buf2 );109printf("---------------------------------------------------\n");110printf("%s\n", wr_buf );111}112curl_easy_cleanup( curl );113114return0;115}116
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/12/27 07:58
2019/12/27 08:41
2019/12/27 08:44
2019/12/27 08:56
2019/12/27 09:06
2019/12/27 10:46
2020/01/07 00:36 編集