如何用c写获取http post表单提交的数据

RT,本人小白,高分求教!要写出详细的程序。

以下方法用CURL提交表单

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++绿色的三角编译运行。
温馨提示:答案为网友推荐,仅供参考

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网