http://blog.csdn.net/unix21/article/details/13629035
2013
官网:http://curl.haxx.se/libcurl/c/libcurl-tutorial.html
#curl-config --libs
得到
-lcurl
#cc libcurl_test.c -o libcurl_test -lcurl
所有的例子:http://curl.haxx.se/libcurl/c/example.html
例子:
- /***************************************************************************
- * _ _ ____ _
- * Project ___| | | | _ \| |
- * / __| | | | |_) | |
- * | (__| |_| | _ <| |___
- * \___|\___/|_| \_\_____|
- *
- * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
- *
- * This software is licensed as described in the file COPYING, which
- * you should have received as part of this distribution. The terms
- * are also available at http://curl.haxx.se/docs/copyright.html.
- *
- * You may opt to use, copy, modify, merge, publish, distribute and/or sell
- * copies of the Software, and permit persons to whom the Software is
- * furnished to do so, under the terms of the COPYING file.
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
- * KIND, either express or implied.
- *
- ***************************************************************************/
- #include <stdio.h>
- #include <curl/curl.h>
-
- int main(void)
- {
- CURL *curl;
- CURLcode res;
-
- /* http://curl.haxx.se/libcurl/c/curl_easy_init.html */
- curl = curl_easy_init();
- if(curl) {
- /* http://curl.haxx.se/libcurl/c/curl_easy_setopt.html#CURLOPTURL */
- curl_easy_setopt(curl, CURLOPT_URL, "http://127.0.0.1/index.html");
- /* http://curl.haxx.se/libcurl/c/curl_easy_perform.html */
- res = curl_easy_perform(curl);
-
- if(CURLE_OK == res) {
- char *ct;
- /* ask for the content-type */
- /* http://curl.haxx.se/libcurl/c/curl_easy_getinfo.html */
- res = curl_easy_getinfo(curl, CURLINFO_CONTENT_TYPE, &ct);
-
- if((CURLE_OK == res) && ct)
- printf("We received Content-Type: %s\n", ct);
- }
-
- /* always cleanup */
- /* http://curl.haxx.se/libcurl/c/curl_easy_cleanup.html */
- curl_easy_cleanup(curl);
- }
- return 0;
- }
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请
点击举报。