1. 編譯環境.
安裝vs2010或其他版本. vs2010 express版也可以。不要低於vc6.
2. 搜索curl-7.25.0.zip,下載。
解壓到c:\curl-7.25.0
打開Visual Studio Command Prompt (2010)
cd \curl-7.25.0\winbuild
nmake /f Makefile.vc mode=dll USE_SSSPI=no ENABLE_IDN=no
編譯成功後 cd ..\builds
到壹個名字為libcurl-....lib的子目錄裏找到libcurl.dll和libcurl.lib, 保存到壹個目錄下備份,下面要用。
3. 打開vc++ 2010, File->New project,選Win32 Project, 輸入壹個項目名。下面點Next,勾上Console Application和Empty Project.
4. 配置項目
到我的文檔下找到vs2010 projects目錄,找到 solution名字\項目名字 目錄,
把curl-7.25.0目錄下的include目錄拷貝到項目目錄下
把2備份好的libcurl.dll和libcurl.lib拷貝到項目目錄.
在vc++中右鍵點擊項目名(或Alt+F7), 點開Configuration Properties, 點vc++directories
點Include Directories, 點Edit, 添加$(ProjectDir)include 確定
在點擊左側的Linker, 點Input,點Additional Dependences, 點Edit, 添加壹行$(ProjectDir)\libcurl.lib 確定
5. 代碼。
右鍵點項目名字,Add New Item->C++ File, name寫main.c, 輸入代碼:
/* 抱歉,這裏不好貼鏈接,版權沒法貼,版權去看http-post.c */
#include <stdio.h>
#include <curl/curl.h>
#include <stdlib.h>
int main(void)
{
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
/* 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, "這裏寫網址");
/* Now specify the POST data */
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "name=daniel&project=curl");
/* Perform the request, res will get the return code */
res = curl_easy_perform(curl);
/* always cleanup */
curl_easy_cleanup(curl);
system("pause");
}
return 0;
}
點vc++綠色的三角編譯運行。