2017-08-14 91 views
0

我正在嘗試使用R訪問我們組織中使用httr GET的網頁。使用httr獲取錯誤401獲取

但是,我收到一條消息,指出由於無效憑證導致訪問被拒絕。 我可以手動執行所需的操作。 似乎授權是自動完成的,當我使用Internet Explorer訪問網站,但訪問被阻止,當試圖做同樣的行動,通過R.

這就是我想要做到這一點: (因爲它是可以只用了組織內部相同的代理服務器地址的內部網絡地址,我不能提供確切的地址)

library(httr) 
r <- GET(myurl, useproxy(myproxyid, 80), verbose()) 

-> GET http: //myurl 
-> host: xxx 
-> User-Agent : libcurl... 
-> Accept-Encoding: gzip, deflate 
-> Proxy-Connection: Keep-Alive 
-> Accept: application/json, text/xml, application/xml, *.* 
<- HTTP/1.1 401 Unauthorized 
<- Content-Type: text/html 
<- Server: Microsoft-IIS/8.5 
<- WWW-Authenticate: Negotiate 
<- WWW-Authenticate: NTLM 
<- X-Powered-By: ASP.NET 

r 

Response [myurl] 
Date 
Status: 401 
... 
<title>401 - Unauthorized: Access is denied due to invalid credentials.</title> 

.... 

我明白,我無論如何都必須把我的證件符合我的要求。 有可能以某種方式使用自動驗證?

感謝 拉斐爾

回答

1

OK

我終於做到了。

我不得不喜歡這個認證數據提供給我get命令:

library(httr) 
r <- GET(myurl, 
     useproxy(myproxyid, 80), 
     verbose(), 
     authenticate(user = "myuserid", password = "mypassword", type = "ntlm")) 

我希望它能幫助任何人

感謝

拉斐爾