我正在尝试制作一篇http帖子,并使用RCurl检索标题信息,我看到了一些奇怪的行为。
会话信息:
> curlVersion()$version
[1] "7.24.0"
> sessionInfo()
R version 3.0.1 (2013-05-16)
Platform: x86_64-apple-darwin10.8.0 (64-bit)
locale:
[1] en_CA.UTF-8/en_CA.UTF-8/en_CA.UTF-8/C/en_CA.UTF-8/en_CA.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] RCurl_1.95-4.1 bitops_1.0-6
我第一次看到奇怪的行为向我的工作api发帖,但是为了确保我尝试了另一个网站,它给了我相同的行为。这很好用:
> response <- postForm("http://posttestserver.com/post.php", stuff="Other stuff")
> response
[1] "Successfully dumped 1 post variables.\nView it at http://www.posttestserver.com/data/2013/10/04/{REDACTED}\nPost body was 0 chars long."
attr(,"Content-Type")
"text/html"
但我也想抓住标题信息,这里是乐趣开始的地方。
> h <- basicHeaderGatherer()
> response <- postForm("http://posttestserver.com/post.php", stuff="Other stuff", .opts=curlOptions(headerfunction=h$update))
Successfully dumped 1 post variables.
View it at http://www.posttestserver.com/data/2013/10/04/{REDACTED}
Post body was 0 chars long.>
> response
NULL
> h$value()
Date Server Access-Control-Allow-Origin Vary Content-Length Content-Type status
"Fri, 04 Oct 2013 18:50:14 GMT" "Apache" "*" "Accept-Encoding" "140" "text/html" "200"
statusMessage
"OK"
响应的颜色(“Sucessfully dumped 1 ... etc”)现在是灰色的,当我没有要求时输出,同时输入V形纹也是如此。响应变量为NULL,但标题看起来很好。然后有这一行(添加verbose = TRUE):
response <- postForm("http://posttestserver.com/post.php", stuff="Other stuff", .opts=curlOptions(headerfunction=h$update, verbose=TRUE))
让R挂起。
我一点也不知道发生了什么,任何帮助或指导方向都会受到高度赞赏。