相关疑难解决方法(0)

如何使用R中的httr对shibboleth多主机名网站进行身份验证

注意:ipums international和ipums usa可能使用相同的系统.ipums usa允许更快的注册.如果您想测试您的代码,请尝试https://usa.ipums.org/usa-action/users/request_access进行注册!

我正在尝试以编程方式从https://international.ipums.org/下载带有R语言和httr的文件.我需要使用httr而不是RCurl因为我需要后验证下载大文件不是 RAM而是直接下载到磁盘. 据我所知,目前这是唯一可行的httr

下面的可重现代码记录了我从登录页面(https://international.ipums.org/international-action/users/login)到主后验证页面的最大努力.任何提示或提示将不胜感激!谢谢!

my_email <- "email@address.com"
my_password <- "password"

tf <- tempfile()

# use httr, because i need to download a large file after authentication
# and only httr supports that with its `write_disk()` option
library(httr)

# turn off ssl verify, otherwise the subsequent GET command will fail
set_config( config( ssl_verifypeer = 0L ) )

GET( "https://international.ipums.org/Shibboleth.sso/Login?target=https%3A%2F%2Finternational.ipums.org%2Finternational-action%2Fmenu" )

# connect to the starting login page of …
Run Code Online (Sandbox Code Playgroud)

post r shibboleth httr

12
推荐指数
1
解决办法
712
查看次数

在RCurl中创建一个C级文件句柄,用于编写下载的文件

在RCurl中,CFILE定义了一个函数和一个类来处理C级文件句柄.从手册:

目的是能够将这些作为选项传递给libcurl,以便它可以从文件读取或写入文件.我们也可以使用R连接执行此操作并指定操作这些连接的回调函数.但是对于大型文件来说,使用C级文件句柄的速度可能会快得多.

没有与下载相关的示例,所以我试过:

library(RCurl)
u = "http://cran.r-project.org/web/packages/RCurl/RCurl.pdf"
f = CFILE("RCurl.pdf", mode="wb")
ret= getURL(u,  write = getNativeSymbolInfo("R_curl_write_binary_data")$address,
                file  = f@ref)
Run Code Online (Sandbox Code Playgroud)

我也尝试用替换file选项writedata = f@ref.该文件已下载但已损坏.为write参数编写自定义回调仅适用于非二进制数据.

有没有想过在RCurl中将二进制文件直接下载到磁盘(不加载到内存中)?

curl r rcurl

7
推荐指数
1
解决办法
786
查看次数

下载大文件时httr GET函数空间不足

我正在尝试下载一个1.1千兆字节的文件,httr但我遇到以下错误:

x <- GET( extract.path )
Error in curlPerform(curl = handle$handle, .opts = curl_opts$values) : 
  cannot allocate more space: 1728053248 bytes
Run Code Online (Sandbox Code Playgroud)

我的C盘有400GB免费..

RCurl包中,我看到maxfilesizemaxfilesize.large使用时的选项,getCurlOptionsConstants()但我不明白是否/如何传递httr通过configset_config..或如果我需要切换到RCurl这... ..即使我确实需要切换,会增加最大文件大小的工作吗?

这是我的sessionInfo ..

> sessionInfo()
R version 3.0.0 (2013-04-03)
Platform: i386-w64-mingw32/i386 (32-bit)

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252    LC_MONETARY=English_United States.1252 LC_NUMERIC=C                           LC_TIME=English_United States.1252    

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

other attached packages:
[1] XML_3.96-1.1 …
Run Code Online (Sandbox Code Playgroud)

r web-scraping rcurl httr

6
推荐指数
1
解决办法
631
查看次数

我的用户名和密码应该放在SOAP api的POST中

我把api电话放在一起.在这一点上,我甚至不确定它是否正确.我需要添加我的用户名和密码,但不知道在哪里.任何有关用户名和密码放置的建议都将不胜感激.

api调用的背景是它是在postman中发送给我的,我可以运行它.我能够从邮递员身上拉出身体,但我需要在API调用中包含身份验证.

在此处输入代码

library(RCurl)

headerFields =
  c(Accept = "text/xml",
    'Content-Type' = "text/xml; charset=utf-8")

body = '<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.sitename.com/bizconnect/SBU">
<SOAP-ENV:Body>
<ns1:GetSBUApplicationData>
<ns1:Subscriber>
<ns1:SubCode>123456</ns1:SubCode>
</ns1:Subscriber>
<ns1:UserID>xxxxxx</ns1:UserID>
<ns1:ReferenceID>A</ns1:ReferenceID>
<ns1:ResponseVersion>010</ns1:ResponseVersion>
<ns1:Application>
<ns1:Id>G020D</ns1:Id>
<ns1:Name/>
<ns1:Key>
<ns1:Field>
<ns1:Id>00920000</ns1:Id>
<ns1:Name/>
<ns1:Value>900000095</ns1:Value>
</ns1:Field>
</ns1:Key>
</ns1:Application>
</ns1:GetSBUApplicationData>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>'

curlPerform(url = "https://stg1-ss1.sitename.com/bizconnect/SBU/service",
            httpheader = headerFields,
            postfields = body
)
Run Code Online (Sandbox Code Playgroud)

api soap r

5
推荐指数
1
解决办法
128
查看次数

标签 统计

r ×4

httr ×2

rcurl ×2

api ×1

curl ×1

post ×1

shibboleth ×1

soap ×1

web-scraping ×1