使用Ruby RestClient发送POST请求的问题

时间:2013-11-19 17:07:03

标签: ruby rest-client

我想提交一个包含Ruby RestClient的表单来获取一些论文的BibTex文件。这是浏览器捕获的请求:

Request URL:
http://ieeexplore.ieee.org/xpl/downloadCitations
Request Method:
POST

Status Code:200 OK (from cache)
Request Payload
recordIds=6665065&citations-format=citation-only&download-format=download-bibtex&x=74&y=7

所以这是我的Ruby脚本:

response = RestClient.post("http://ieeexplore.ieee.org/xpl/downloadCitations", "recordIds"=> 6665065, "citations-format" => "citation-only", "download-format" => "download-bibtex", "x" => "74", "y" => "7"){|response, request, result, &block|
                    if [301, 302, 307].include?(response.code)
                            puts response
                    else
                            response.return!(request, result, &block)
                    end
            }
puts response

虽然我可以直接在我的浏览器中获得正确的结果,但脚本仍然会返回:

<html><head><title>302 Moved Temporarily</title></head>
<body bgcolor="#FFFFFF">
<p>This document you requested has moved temporarily.</p>
<p>It's now at <a href="http://ieeexplore.ieee.org:80/xpl/downloadCitations?reload=true">http://ieeexplore.ieee.org:80/xpl/downloadCitations?reload=true</a>.</p>
</body></html>

有人知道为什么会这样吗? 谢谢!

1 个答案:

答案 0 :(得分:0)

相关问题