我尝试使用POST功能使用 httr 库访问R中的以下网址。我需要提取已开发脚本的一些货币汇率。我在验证工具内部有不同的时间段时遇到问题。
https://www.oanda.com/fx-for-business/historical-rates/auth/login/
我使用以下代码
library(httr)
Cookie = paste('opc_id=599C877C-7B4C-11E7-A634-FD6593E2D6B9;', 'csrftoken=EJqIgiufV77Nlv4E54mKoFcxhKGJgnO4cdQzUy2ehaayjD5FX21F8MznpHm0o4W5;','sessionid "6bc5s0qnswsue0pxe3st83ezf6m9cdl5;')
headers = list (
Host= "www.oanda.com",
"User-Agent" = "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:54.0) Gecko/20100101 Firefox/54.0",
Accept = "*/*",
"Accept-Language" = "en-US,en;q=0.5",
"Accept-Encoding" = "gzip, deflate, br",
"Content-Type"= "application/x-www-form-urlencoded; charset=UTF-8",
Referer = "https://www.oand
a.com/fx-for-business/historical-rates",
"Content-Length" = 64,
"X-Requested-With" = "XMLHttpRequest",
Cookie = Cookie, Connection= "keep-alive")
.headers = character(headers)
par = list (
email = "user",
password = "pass",
redirect=""
)
POST("https://www.oanda.com/fx-for-business/historical-rates/auth/login/",body = pars, add_headers(.headers))
最后一行的结果如下。该脚本需要CSFR令牌,我该如何生成它?
<h1>Forbidden
<span>(403)</span>
</h1>
<p>CSRF verification failed. Request aborted.</p>
<p>You are seeing this message because this site requires a CSRF cookie when submitting forms. This cookie is required for security reasons, to ensure that your browser is not being hijacked by third parties.</p>
<p>If you have configured your browser to disable cookies, please re-enable them, at least for this site, or for 'same-origin' requests.</p>
GET&amp;的结构。 POST是以下
GET https://www.oanda.com/static/sfb/hcc/templates/html/en/popup.login.html?_=1502097958941
POST https://www.oanda.com/fx-for-business/historical-rates/auth/login/
GET https://www.oanda.com/fx-for-business/historical-rates/getUser/?_=1502097958942
GET https://www.oanda.com/fx-for-business/historical-rates/message/messages/?_=1502097958943
GET https://www.oanda.com/static/sfb/hcc/templates/html/en/banner.expiry.html?_=1502097958944
GET https://www.oanda.com/static/sfb/hcc/templates/html/en/popup.login.success.html?_=1502097958945
答案 0 :(得分:1)
解决方案在于模拟R内部的Web浏览器。 实现此目的的代码如下
$('.selLang').hover(function() {
$("#myDialog").dialog('option', 'draggable', false);
},function(){
$("#myDialog").dialog('option', 'draggable', true);
})