gpt4 book ai didi

r - 获取响应头

转载 作者:行者123 更新时间:2023-12-04 20:13:36 25 4
gpt4 key购买 nike

我想从 GET 或 POST 获取响应 header 。

我的例子是:

    library(httr)
library(RCurl)
url<-'http://www.omegahat.org/RCurl/philosophy.html'
doc<-GET(url)
names(doc)

[1] "url" "handle" "status_code" "headers" "cookies" "content" "times" "config"

但是没有响应头,只有请求头。

结果应该是这样的:
Connection:Keep-Alive
Date:Mon, 11 Feb 2013 20:21:56 GMT
ETag:"126a001-e33d-4c12cf2702440"
Keep-Alive:timeout=15, max=100
Server:Apache/2.2.14 (Ubuntu)
Vary:Accept-Encoding

我可以使用 R 和 httr/RCurl 包来做到这一点,还是 R 不足以解决此类问题?

编辑 : 我想得到所有的响应头。我主要对 感兴趣地点 不在此示例中的响应。

编辑 2 : 我忘了告诉我工作的系统 - 它是 Windows 7

我的 session.info
> sessionInfo()
R version 2.15.2 (2012-10-26)
Platform: x86_64-w64-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=Polish_Poland.1250 LC_CTYPE=Polish_Poland.1250 LC_MONETARY=Polish_Poland.1250
[4] LC_NUMERIC=C LC_TIME=Polish_Poland.1250

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] rjson_0.2.12 RCurl_1.95-3 bitops_1.0-5 httr_0.2 XML_3.95-0.1

loaded via a namespace (and not attached):
[1] digest_0.6.2 stringr_0.6.2 tools_2.15.2

最佳答案

你可以这样做:

h <- basicHeaderGatherer()
doc <- getURI("http://www.omegahat.org/RCurl/index.html", headerfunction = h$update)
h$value()

这会给你一个命名向量:
                            Date                           Server 
"Mon, 11 Feb 2013 20:41:58 GMT" "Apache/2.2.14 (Ubuntu)"
Last-Modified ETag
"Wed, 24 Oct 2012 15:49:35 GMT" "\"3262089-10bf-4ccd0088461c0\""
Accept-Ranges Content-Length
"bytes" "4287"
Vary Content-Type
"Accept-Encoding" "text/html"
status statusMessage
"200" "OK"

关于r - 获取响应头,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14820286/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com