php使用curl获取数据_使用cURL获取单个标题

php使用curl获取数据

Debugging third party apps can be difficult for a variety of reasons.  You take for granted that the third party has not only properly coded their app but that their server is also serving files properly.  As more a developer than a sysadmin I tend to spend a long time on the code before I ensure the server stuff is correct.  One mistake often made on the server side is not sending correct Content-Type headers with content, especially audio and video files, and that can cause a real problem for the app or codec trying to do something with the content.  These days I check response headers before I do anything else.

出于多种原因,调试第三方应用可能很困难。 您认为第三方不仅已正确编码了他们的应用程序,而且他们的服务器也正在正确地提供文件。 作为一名开发人员而不是系统管理员,我倾向于在确保服务器配置正确之前花大量时间在代码上。 在服务器端经常犯的一个错误是没有发送带有内容的正确的Content-Type标头,尤其是音频和视频文件,这可能会导致应用或编解码器尝试对内容进行处理的真正问题。 这些天,我在做其他事情之前先检查响应头。

Getting complete response headers with cURL is easy:

使用cURL获取完整的响应标头很容易:


#  Get response headers
curl -I https://davidwalsh.name

#  Result:
#  HTTP/1.1 301 Moved Permanently
#  Date: Wed, 03 Feb 2016 17:29:51 GMT
#  Content-Type: text/html; charset=iso-8859-1
#  Connection: keep-alive
#  Set-Cookie: __cfduid=dab1e532a38b35ce7d764344217ddd8dc1454520590; expires=Thu, 02-Feb-17 17:29:50 GMT; path=/; domain=.davidwalsh.name; HttpOnly
#  Location: https://davidwalsh.name/
#  Cache-Control: max-age=1
#  Expires: Wed, 03 Feb 2016 17:29:52 GMT
#  Vary: Accept-Encoding
#  Server: cloudflare-nginx
#  CF-RAY: 26efdc3d2aa841ef-MSP


But that's a lot of info to sift through if you only want the one header.  Here's how you can retrieve just one header:

但是,如果您只想要一个标头,则需要筛选很多信息。 这是仅检索一个标头的方法:


#  Get single header only
#  curl {url} -I | grep -Fi {header_name}
curl https://davidwalsh.name -I | grep -Fi Content-Type

#  Result:
#  Content-Type: text/html; charset=iso-8859-1


With the extra grep above you'll only get the one header back.  Simple!

使用上面的额外grep ,您只会获得一个标头。 简单!

翻译自: https://davidwalsh.name/curl-get-header

php使用curl获取数据

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值