您的位置:首页 > 理论基础 > 计算机网络

怎样使用libcurl获取隐藏了文件后缀的url网络文件类型

2017-03-10 17:51 736 查看
CURLINFO_CONTENT_TYPE

CURL: Get Returned Content Mime Type

例如 :以下代码可以查询出天地图的tile图像类型为jpg

"http://t0.tianditu.com/img_c/wmts/wmts?Service=WMTS&Request=GetTile&Version=1.0.0&Style=Default&Format=tiles&serviceMode=KVP&layer=img&TileMatrixSet=c&TileMatrix=1&TileRow=0&TileCol=0"

// Store the mime-type, if any. (Note: CURL manages the buffer returned by
// this call.)
char* ctbuf = NULL;
if ( curl_easy_getinfo(_curl, CURLINFO_CONTENT_TYPE, &ctbuf) == 0 && ctbuf )
{
sp._resultMimeType = ctbuf;
}

跟踪发现 ctbuf 为 "image/jpeg"

可参考 http://www.satya-weblog.com/2010/07/php-curl-get-returned-content-mime-type.html。 内容相同
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: