'programming/C_C++'에 해당되는 글 279건

  1. 2013.08.27 curl example

curl example

programming/C_C++ 2013. 8. 27. 13:53
반응형

http://yungyikim.com/576

 

[Install]
./configure --prefix=설치경로
make
make install

 

[Example]

 

CURL *curl;
CURLcode res;
struct curl_slist *chunk = NULL;
 
curl = curl_easy_init();
if(curl) {
    char* params = "type=a&message=m";
 
    chunk = curl_slist_append(chunk, "Content-Type: application/x-www-form-urlencoded");
 
    /* First set the URL that is about to receive our POST. This URL can
    just as well be a https:// URL if that is what should receive the
    data. */
    curl_easy_setopt(curl, CURLOPT_URL, "https://sample.co.kr");
 
    res = curl_easy_setopt(curl, CURLOPT_HTTPHEADER, chunk);    // 헤더 등록
     
    /* Now specify the POST data */
    curl_easy_setopt(curl, CURLOPT_POSTFIELDS, params);
    curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)strlen(params));    // 내용 등록
     
    /* Perform the request, res will get the return code */
    res = curl_easy_perform(curl);  // 실제 호출
 
    /* always cleanup */
    curl_easy_cleanup(curl);
}
반응형
Posted by 공간사랑
,