如何用CURL并解释JSON
CURL *curl;
CURLcode res;
struct curl_slist *headers=NULL; // init to NULL is important
headers = curl_slist_append(headers, "Accept: application/json");
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "http://web.com/api/json/123");//cant get json file
curl_easy_setopt(curl, CURLOPT_URL, "http://web.com/pages/123.html");//this returns entire webpage
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_RETURNTRANSFER, true);
res = curl_easy_perform(curl);
if(CURLE_OK == res) {
char *ct;
// ask for the content-type
res = curl_easy_getinfo(curl, CURLINFO_CONTENT_TYPE, &ct);
if((CURLE_OK == res) && ct)
printf("We received Content-Type: %s\n", ct);
}
}
// always cleanup
curl_easy_cleanup(curl);
//参考答案1
std::string ServerContent::DownloadJSO
{
CURL *curl;
CURLcode res;
struct curl_slist *headers=NULL; // init to NULL is important
std::ostringstream oss;
curl_slist_append(headers, "Accept: application/json");
curl_slist_append( headers, "Content-Type: application/json");
curl_slist_append( headers, "charsets: utf-8");
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_URL, URL.c_str());
curl_easy_setopt(curl, CURLOPT_HTTPGET,1);
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl,CURLOPT_WRITEFUNCTION,writer);
res = curl_easy_perform(curl);
if(CURLE_OK == res) {
char *ct;
res = curl_easy_getinfo(curl, CURLINFO_CONTENT_TYPE, &ct);
if((CURLE_OK == res) && ct)
return *DownloadedResponse;
}
}
}
如何用CURL并解释JSON的更多相关文章
- 格式化Curl返回的Json字符
格式化Curl返回的Json字符 学习了:https://blog.csdn.net/guijiaoba/article/details/78235523 , 使用python工具 curl xxx ...
- Curl之Post Json
curl Post Json $ curl -i -X POST -H "'Content-type':'application/x-www-form-urlencoded', 'chars ...
- curl中通过json格式吧post值返回到java中遇到中文乱码的问题
首先是: curl中模拟http请求: curl -l 127.0.0.1:8080/spacobj/core/do?acid=100 -H "token:101hh" -H &q ...
- 命令行获取zabbix最新的issues - jq 解释json
0.安装jq wget -O jq https://github.com/stedolan/jq/releases/download/jq-1.5/jq-linux64 chmod +x ./jq c ...
- curl模拟post json或post xml文件
转自: https://www.cnblogs.com/xiaochina/p/9750851.html 问题描述: Linux用命令模拟接口,对接口判断!post文件xml/json 问题解决: c ...
- php同curl post 发送json并返回json数据实例
<?php $arr = array( 'subject'=>'课程', 'loginName'=>'Durriya', 'password'=>'123' ); //json ...
- curl 命令返回json结构human readable
在curl命令后面添加 | python -m json.tool 不想显示curl的统计信息,添加 -s参数 例: curl https://news-at.zhihu.com/api/4/news ...
- solr curl索引 CSV/Json/xml文件
在windows系统中,用curl命令工具索引文件命令: 启动solr 在solr-6.6.0\bin的同级目录下的文件夹ImportData下要索引的文件. 1.索引 json文件 curl &qu ...
- curl post 用json方式
if(!function_exists('tps_curl_post3')){ function tps_curl_post3($url, $postData) { $postData = json_ ...
随机推荐
- SQL Server 2012 内存管理 (memory management) 改进
SQL Server 2012 的内存管理和以前的版本相比,有以下的一些变化. 一.内存分配器的变化 SQL Server 2012以前的版本,比如SQL Server 2008 R2等, 有sing ...
- Html5时钟的实现
最近准备把自己的博客装修一下,首先,先为自己设计一个时钟吧,希望博客园能够尽快发放给我使用js的权限! 自从看见了苹果设计的那款因为侵权而赔钱了时钟,我就决定我的时钟一定是要参考这个来设计了! 不得不 ...
- Android Toast 总结(五种用法)
Toast大家都很熟,不多说.直接上图上代码. 具体代码如下: main.xml: <?xml version="1.0" encoding="utf-8" ...
- java String的equals,intern方法(转载)
JAVA中的equals和==的区别 ==比较的是2个对象的地址,而equals比较的是2个对象的内容. 显然,当equals为true时,==不一定为true: 基础知识的重要性,希望引起大家的重视 ...
- Registry uninstall values
Original link: http://windowssucks.wordpress.com/win-registry-uninstall-values/ -------------------- ...
- (转)boost::bind介绍
转自:http://www.cnblogs.com/sld666666/archive/2010/12/14/1905980.html 这篇文章介绍boost::bind()的用法, 文章的主要内容是 ...
- Poj 1503 Integer Inquiry
1.链接地址: http://poj.org/problem?id=1503 2.题目: Integer Inquiry Time Limit: 1000MS Memory Limit: 1000 ...
- 鸟哥私房菜笔记:Iptables:数据包过滤软件
数据包进入流程:规则顺序的重要性 iptables利用的是数据包过滤机制,所以它会分析数据包的包头数据.根据包头数据与定义的规则来决定该数据包是否可以进入主机或者是被丢弃.也就是说,根据数据包的分析资 ...
- React:用于搭建UI的JavaScript库
React https://facebook.github.io/react/index.html 2016-08-03 先吐槽一下.看过很多博客.教程.文章,一直想不通为什么大牛们介绍一种新技术一上 ...
- 解决VS2008打开假死或者打开设计模式假死的问题
我昨天刚装完OFFICE 2010一直也没重启,vs2008是可以使用的.今早来到办公室,打开工程发现开了半天VS2008一般空白,查看应用程序显示正在运行,再查看进程发现里面多一个setup.exe ...