如何用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_ ...
随机推荐
- Shell中read的选项及用法
1. Read的一些选项 Read可以带有-a, -d, -e, -n, -p, -r, -t, 和 -s八个选项. -a :将内容读入到数值中 echo -n "Input muliple ...
- String类中toCharArray()方法的用法
该方法的作用是返回一个字符数组,该字符数组中存放了当前字符串中的所有字符 eg: public class class6_3 { public static void main(String arg ...
- 12天学好C语言——记录我的C语言学习之路(Day 12)
12天学好C语言--记录我的C语言学习之路 Day 12: 进入最后一天的学习,用这样一个程序来综合考量指针和字符串的关系,写完这个程序,你对字符串和指针的理解应该就不错了. //输入一个字符串,内有 ...
- 关于css中的align-content属性详解
align-content 作用: 会设置自由盒内部各个项目在垂直方向排列方式. 条件:必须对父元素设置自由盒属性display:flex;,并且设置排列方式为横向排列flex-direction:r ...
- WPF 关于XDocument(xml) 的部分操作记录
(1)删除xml文件中的一个结点的方法,有如下两种方式(只有存在数据绑定的情况下才会有第二种情况,否则一般是第一种情况): private void DeletePacsNode() { //从xml ...
- mysql常见的hint(转载的)
mysql常用的hint对于经常使用oracle的朋友可能知道,oracle的hint功能种类很多,对于优化sql语句提供了很多方法.同样,在mysql里,也有类似的hint功能.下面介绍一些常用的. ...
- AngularJS(4)-服务(Service)
1.$location服务 $location 服务,它可以返回当前页面的 URL 地址 2.$http服务 $http 是 AngularJS 应用中最常用的服务. 服务向服务器发送请求,应用响应服 ...
- linux shell命令的常用快捷键
一些shell的常用快捷键. Ctrl + a 切换到命令行开始 Ctrl + e 切换到命令行末尾 Ctrl + l 清除屏幕内容 Ctrl + u 清除剪切光标之前的内容 Ctrl + ...
- Android开发中activity切换动画的实现
(1)我们在MainAcitvity中定义两个textview,用于点击触发切换Activity事件,下面是布局文件代码. <LinearLayout android:layout_width= ...
- [转载]C#读取Excel几种方法的体会
C#读取Excel几种方法的体会 转载地址:http://developer.51cto.com/art/201302/380622.htm (1) OleDb: 用这种方法读取Excel速度还是非常 ...