httr'客户端错误:(407)需要代理验证'

时间:2016-08-03 08:19:04

标签: r proxy rcurl httr

我已经在防火墙后面,因此使用代理。

library(httr)

set_config(
  use_proxy(url="18.91.12.23", port=8080)  
)
r <- GET('http://httpbin.org/get',verbose())
http_status(r)

这是显示的错误:

 r <- GET('http://httpbin.org/get',verbose())
-> GET http://httpbin.org/get HTTP/1.1
-> Host: httpbin.org
-> User-Agent: libcurl/7.47.1 r-curl/0.9.7 httr/1.2.1
-> Accept-Encoding: gzip, deflate
-> Proxy-Connection: Keep-Alive
-> Cookie: BCSI-CS-342e9f19b1226740=2
-> Accept: application/json, text/xml, application/xml, */*
-> 
<- HTTP/1.1 407 Proxy Authentication Required
<- Proxy-Authenticate: NTLM
<- Proxy-Authenticate: BASIC realm="onmi"
<- Cache-Control: no-cache
<- Pragma: no-cache
<- Content-Type: text/html; charset=utf-8
<- Proxy-Connection: close
<- Set-Cookie: BCSI-CS-342e9f19b1226740=2; Path=/
<- Connection: close
<- Content-Length: 3645
<- 
> http_status(r)
$category
[1] "Client error"

$reason
[1] "Proxy Authentication Required"

$message
[1] "Client error: (407) Proxy Authentication Required"

我已尝试在我的Internet Explorer中使用Sys.setenv(),with_config(use_proxy())设置代理。但这些都不起作用,而且我得到了相同的客户端错误407.

我尝试过使用不同的网址进行GET,POST但是又一次出现了相同的错误。请帮忙!

1 个答案:

答案 0 :(得分:0)

代理要求提供身份验证凭据,响应代码表示代理将接受基本凭据(用户名/密码)以及NTLM凭据。这些之间最简单的区别是,如果流量被嗅探,则使用基本凭据模式可以看到密码。 NTLM也是一个握手过程,而基本凭证是一个请求通信。

使用基本凭证的示例:

use_proxy(url = "18.91.12.23", port = 8080, username = "username-you-wish-to-use", password = "password-you-wish-to-use", auth = "basic")

使用ntlm凭据的示例:

use_proxy(url = "18.91.12.23", port = 8080, username = "username-you-wish-to-use", password = "password-you-wish-to-use", auth = "ntlm")