卷毛-检索标头-空响应 [英] Curl - Retrieve headers - empty response

查看:116
本文介绍了卷毛-检索标头-空响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用curl时使用php。

Using php when working with curl.

我试图只接收标头。

我从以下网址请求: http://halens.se / kvinna-klader-bad-strand-baddrakter-93 / baddrakt-074209 /

我的设置如下:

  CURLOPT_AUTOREFERER     => true,
  CURLOPT_CERTINFO        => false,
  CURLOPT_CRLF            => true,
  CURLOPT_CONNECTTIMEOUT  => 15,
  CURLOPT_FAILONERROR     => true,
  CURLOPT_FOLLOWLOCATION  => true,
  CURLOPT_FORBID_REUSE    => true,
  CURLOPT_FRESH_CONNECT   => true,
  CURLOPT_HEADER          => true,
  CURLOPT_MAXREDIRS       => 15,
  CURLOPT_PROTOCOLS       => CURLPROTO_HTTP,
  CURLOPT_REDIR_PROTOCOLS => CURLPROTO_HTTP,
  CURLOPT_RETURNTRANSFER  => true,
  CURLOPT_SSL_VERIFYPEER  => false,
  CURLOPT_TIMEOUT         => 15,
  CURLOPT_HEADER          => true,
  CURLOPT_NOBODY          => true

但是响应为空。.我做错了什么?我们如何以其他方式解决此问题?

如果我改了最后一个设置为:

If I instead change the last setting to:

  CURLOPT_NOBODY          => false

然后我得到标题:

HTTP/1.1 301 Moved Permanently
Content-Length: 199
Content-Type: text/html; charset=UTF-8
Location: http://www.halens.se/kvinna-klader-bad-strand-baddrakter-93/baddrakt-074209/
Server: Microsoft-IIS/7.5
X-Powered-By: ARR/2.5
X-Powered-By: ASP.NET
Date: Sun, 06 Oct 2013 19:26:31 GMT

HTTP/1.1 200 OK
Cache-Control: private
Content-Length: 123009
Content-Type: text/html; charset=utf-8
Server: Microsoft-IIS/7.5
Set-Cookie: ASP.NET_SessionId=wsp1hsdq1huvdnmr0jf42m1o; path=/; HttpOnly
Set-Cookie: ASP.NET_SessionId=wsp1hsdq1huvdnmr0jf42m1o; path=/; HttpOnly
Set-Cookie: FavoriteList=Id=593cd25e-3508-46a8-9596-66bd45caa335&Hash=PRHTFWRFDX; expires=Sat, 04-Jan-2014 20:26:32 GMT; path=/
Set-Cookie: InteractorId=wsp1hsdq1huvdnmr0jf42m1o_162_13_85_148; path=/
Set-Cookie: ClickTrail=074209; expires=Thu, 05-Dec-2013 20:26:32 GMT; path=/
X-Powered-By: ARR/2.5
X-Powered-By: ASP.NET
Date: Sun, 06 Oct 2013 19:26:32 GMT


推荐答案

对于具体问题没有答案:似乎有点奇怪和谷歌搜索我可以看到其他人也在这个问题上苦苦挣扎(没有进一步解释)-但是您是否知道 get_headers 函数?

Not an answer to the specific : It seems a little bit weird and googling around I can see other people have struggling with this issue also (without getting closer to an explanation) - but are you aware of the get_headers function?

$header = get_headers('http://halens.se/kvinna-klader-bad-strand-baddrakter-93/baddrakt-074209/');
echo '<pre>';
print_r($header);
echo '</pre>';

输出

Array
(
    [0] => HTTP/1.1 301 Moved Permanently
    [1] => Content-Length: 199
    [2] => Content-Type: text/html; charset=UTF-8
    [3] => Location: http://www.halens.se/kvinna-klader-bad-strand-baddrakter-93/baddrakt-074209/
    [4] => Server: Microsoft-IIS/7.5
    [5] => X-Powered-By: ARR/2.5
    [6] => X-Powered-By: ASP.NET
    [7] => Date: Sun, 06 Oct 2013 21:17:44 GMT
    [8] => Connection: close
    [9] => HTTP/1.1 200 OK
    [10] => Cache-Control: private
    [11] => Content-Length: 123078
    [12] => Content-Type: text/html; charset=utf-8
    [13] => Server: Microsoft-IIS/7.5
    [14] => Set-Cookie: ASP.NET_SessionId=i5nrsl55e1shp4alanw3dlzu; path=/; HttpOnly
    [15] => Set-Cookie: ASP.NET_SessionId=i5nrsl55e1shp4alanw3dlzu; path=/; HttpOnly
    [16] => Set-Cookie: FavoriteList=Id=51b514b9-21e8-4ed3-9ec9-38ef8a2df113&Hash=VKSZPIUFZX; expires=Sat, 04-Jan-2014 22:17:44 GMT; path=/
    [17] => Set-Cookie: InteractorId=i5nrsl55e1shp4alanw3dlzu_80_163_1_60; path=/
    [18] => Set-Cookie: ClickTrail=074209; expires=Thu, 05-Dec-2013 22:17:44 GMT; path=/
    [19] => X-Powered-By: ARR/2.5
    [20] => X-Powered-By: ASP.NET
    [21] => Date: Sun, 06 Oct 2013 21:17:44 GMT
    [22] => Connection: close
)

这篇关于卷毛-检索标头-空响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆