如何用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_ ...
随机推荐
- linux时间自动同步
1,修正本地时区及ntp服务 #yum -y install ntp#rm -rf /etc/localtime#ln -s /usr/share/zoneinfo/Asia/Shanghai /et ...
- ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost' (10061)
http://wandering192.iteye.com/blog/758954 谢谢作者
- 关于char 指针变量char *=p;这个语句的输出问题
学习指针的时候我一直有个疑惑,请看下面的代码: #include <iostream> using std::cout; void main() { ; int *nPtr=&nu ...
- C bit 操作
C 位 操作 一.C bit 操作(C语言 二进制位 操作) 1.Setting a bit Use the bitwise OR operator (|) to set a bit. number ...
- C语言经典案例
题目:企业发放的奖金根据利润提成.利润(I)低于或等于10万元时,奖金可提10%:利润高于10万元,低于20万元时,低于10万元的部分按10%提成,高于10万元的部分,可可提成7.5%:20万到40万 ...
- UVA - 297 Quadtrees (四分树)
题意:求两棵四分树合并之后黑色像素的个数. 分析:边建树边统计. #include<cstdio> #include<cstring> #include<cstdlib& ...
- hdu 1063 Exponentiation (高精度小数乘法)
//大数继续,额,要吐了. Problem Description Problems involving the computation of exact values of very large m ...
- ExecutorService 接口
先看一个Executor接口,该接口只有一个方法:void execute(Runnable command),用于在未来某个时刻提交一个command,这个command可以被提交到一个新的线程,或 ...
- iOS 多态的简单思想
/** * 多态:多种形态,是对于对象而言的,如果没有继承就没有多态 * * 在代码中体现:就是通过定义父类指针指向子类的对象 * * 好处:在函数或者方法的参数中如果传入的是父类指针,那么实现的时候 ...
- Nwjs从入门到精通 菜鸟实践笔记【1】
最近公司有想使用Nw来开发浏览器的想法,自己一直学的PHP,在网上并没有找到太多的相关资料,所以,就自己摸索着撸一条自学笔记: 当然呢,这里记录的都是我自己学习中遇到的问题,以及收获,希望通过自己的分 ...