我正在尝试发布 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"
响应的颜色(“成功转储 1...等”)现在是灰色的,并在我没有要求时输出,同时缩进输入 V 形。响应变量为 NULL,但标头看起来不错。然后是这一行(添加verbose = TRUE):
response <- postForm("http://posttestserver.com/post.php", stuff="Other stuff", .opts=curlOptions(headerfunction=h$update, verbose=TRUE))
只是让 R 挂起。
我一点也不知道发生了什么,任何帮助或寻找方向将不胜感激。