c里面使用libcurl库实现发送post并获取post到的内容
来源:互联网 发布:starbound mac 汉化 编辑:程序博客网 时间:2024/06/02 04:45
以下是c代码的实现:
#include <stdio.h>#include <stdlib.h>#include <string.h>#include <curl/curl.h>#define POSTURL "http://www.xiami.com/member/login"#define POSTFIELDS "email=myemail@163.com&password=mypassword&autologin=1&submit=登 录&type="#define FILENAME "curlposttest.log"size_t write_data(void* buffer,size_t size,size_t nmemb,void *stream){FILE *fptr = (FILE*)stream;fwrite(buffer,size,nmemb,fptr);return size*nmemb;}int main(int argc,char *argv[]){CURL *curl;CURLcode res;FILE* fptr;struct curl_slist *http_header = NULL;if ((fptr = fopen(FILENAME,"w")) == NULL){fprintf(stderr,"fopen file error:%s\n",FILENAME);return -1;}curl = curl_easy_init();if (!curl){fprintf(stderr,"curl init failed\n");return -1;}curl_easy_setopt(curl,CURLOPT_URL,POSTURL); //url地址curl_easy_setopt(curl,CURLOPT_POSTFIELDS,POSTFIELDS); //post参数curl_easy_setopt(curl,CURLOPT_WRITEFUNCTION,write_data); //对返回的数据进行操作的函数地址curl_easy_setopt(curl,CURLOPT_WRITEDATA,fptr); //这是write_data的第四个参数值curl_easy_setopt(curl,CURLOPT_POST,1); //设置问非0表示本次操作为postcurl_easy_setopt(curl,CURLOPT_VERBOSE,1); //打印调试信息curl_easy_setopt(curl,CURLOPT_HEADER,1); //将响应头信息和相应体一起传给write_datacurl_easy_setopt(curl,CURLOPT_FOLLOWLOCATION,1); //设置为非0,响应头信息locationcurl_easy_setopt(curl,CURLOPT_COOKIEFILE,"/Users/zhu/CProjects/curlposttest.cookie");res = curl_easy_perform(curl);if (res != CURLE_OK){switch(res){case CURLE_UNSUPPORTED_PROTOCOL:fprintf(stderr,"不支持的协议,由URL的头部指定\n");case CURLE_COULDNT_CONNECT:fprintf(stderr,"不能连接到remote主机或者代理\n");case CURLE_HTTP_RETURNED_ERROR:fprintf(stderr,"http返回错误\n");case CURLE_READ_ERROR:fprintf(stderr,"读本地文件错误\n");default:fprintf(stderr,"返回值:%d\n",res);}return -1;}curl_easy_cleanup(curl);}
- c里面使用libcurl库实现发送post并获取post到的内容
- c里面使用libcurl库实现发送post并获取post到的内容
- 使用libcurl发送post请求
- http的post方式连接服务器,发送数据到服务端,并获取服务端的数据
- post json数据到springmvc中并获取http请求的内容
- libcurl库的http get和http post使用
- libcurl库的http get和http post使用
- c++ 使用libcurl 发送http get/post请求
- c++ 使用libcurl 发送http get/post请求
- iOS网络篇---使用NSSession 实现post和get发送和接收,并实现字典的发送
- 基于nginx的C模块代码实现获取POST请求参数并回传给客户端
- 使用libcurl提交POST请求
- 使用libcurl提交POST请求
- 使用libcurl提交POST请求
- 使用libcurl提交POST请求
- 使用libcurl提交POST请求
- C/C++使用libcurl库发送http请求(get和post可以用于请求html信息,也可以请求xml和json等串)
- 发送post请求到https的url
- PHP empty() & isset()
- ZOJ 3686 线段树
- PushNotification教程–客户端到服务器(PHP)一条龙服务
- 上海云计算培训——Cloud Essential云计算精要认证培训 云计算技术 云计算概念
- synchronized浅析
- c里面使用libcurl库实现发送post并获取post到的内容
- Ie6 Ie7 双倍padding问题
- Hadoop的十大应用领域 云计算是什么 云计算技术 云计算基础 云计算概念 云计算平台
- iBaties的简单入门案例
- qt界面 “父—子”类继承,及析构关系
- 内核模块编写helloworld
- 在Ubuntu上为Android系统编写Linux内核驱动程序
- 如何在没有word的情况下查看docx文档
- 窄字节转换成宽字节 char转换成unicode