libcurl使用笔记
来源:互联网 发布:淘宝漏洞,免费买衣服 编辑:程序博客网 时间:2024/05/22 06:28
curl:
GET: curl -vG -d “test=string” http://127.0.0.1
不加-G是POST
直接curl 127.0.0.1是GET
直接curl -v http://127.0.0.1/xxx?test=string&test2=string2 是GET,但是无法发送&test2=string2
POST: curl -vX POST -d “test=string” http://127.0.0.1
libcurl:
libcurl returns CURLE_OK when the transfer went fine. Getting a 404 from a HTTP server is considered a fine transfer.
The response code is only going to be set if curl_easy_perform() returns CURLE_OK so you should check that first to make sure curl actually performed the request successfully.
POST请求到没有server的地址拿不到http code。只有GET能拿到。
用GET调curl_easy_setopt(curl_handle, CURLOPT_URL, url);的时候,url中必须是完整的请求http://127.0.0.1/xxx?test=string&test2=string2。
用POST时url里只需要是http://127.0.0.1/xxx? ,然后再调curl_easy_setopt(curl_handle, CURLOPT_COPYPOSTFIELDS, request);
OPT:
libcurl默认是用GET
/* * Initialize the UserDefined fields within a SessionHandle. * This may be safely called on a new or existing SessionHandle. */CURLcode Curl_init_userdefined(struct UserDefined *set){ set->httpreq = HTTPREQ_GET; /* Default HTTP request */}
curl_easy_setopt(curl_handle, CURLOPT_VERBOSE, 1);相当于-v
case CURLOPT_VERBOSE: /* * Verbose means infof() calls that give a lot of information about * the connection and transfer procedures as well as internal choices. */ data->set.verbose = (0 != va_arg(param, long))?TRUE:FALSE; break;
curl_easy_setopt(curl_handle, CURLOPT_POST, 1);1为用POST,0为用GET
case CURLOPT_POST: /* Does this option serve a purpose anymore? Yes it does, when CURLOPT_POSTFIELDS isn't used and the POST data is read off the callback! */ if(va_arg(param, long)) { data->set.httpreq = HTTPREQ_POST; data->set.opt_no_body = FALSE; /* this is implied */ } else data->set.httpreq = HTTPREQ_GET; break;
curl_easy_setopt(curl_handle, CURLOPT_COPYPOSTFIELDS, 1);也是用POST
case CURLOPT_COPYPOSTFIELDS: /* * A string with POST data. Makes curl HTTP POST. Even if it is NULL. * If needed, CURLOPT_POSTFIELDSIZE must have been set prior to * CURLOPT_COPYPOSTFIELDS and not altered later. */ data->set.httpreq = HTTPREQ_POST; break;
curl_easy_setopt(curl_handle, CURLOPT_HTTPGET, 1);1为用GET,0啥也不干
case CURLOPT_HTTPGET: /* * Set to force us do HTTP GET */ if(va_arg(param, long)) { data->set.httpreq = HTTPREQ_GET; data->set.upload = FALSE; /* switch off upload */ data->set.opt_no_body = FALSE; /* this is implied */ } break;
- libcurl使用笔记
- libcurl使用笔记
- libcurl基本使用 -- libcurl
- libcurl使用学习笔记(一)
- libcurl学习使用笔记(二)
- libcurl 笔记
- libcurl使用
- libcurl使用
- 使用libcurl
- libcurl使用
- libcurl 使用
- libcurl使用
- libcurl使用心得libcurl使用心得
- libcurl 学习笔记
- libcurl学习笔记
- 学习笔记2 -- libcurl
- libcurl用法笔记
- libcurl库学习笔记
- 批量修改文件时间
- 快速理解Kafka分布式消息队列框架
- 黑马程序员_java基础加强学习笔记之注解
- 判断textField为空时让按钮不可用的代码
- 使用WebClient自动填写并提交ASP.NET页面表单的源代码
- libcurl使用笔记
- 使用cwRsync实现windows下文件定时同步(备份)
- REST介绍
- java上传、下载、删除ftp文件
- (001):获取数据源
- 眼部带状疱疹
- DBsql数据库操作的方法
- java数字格式中文化
- 两个服务器之间的数据数据交换的核…