R中URL的最大长度是多少?

What is the maximum length of URL in R?

我正在用 R 构建一个 URI,它是用 ~40000 个字符动态生成的。

我尝试使用

当通过 HTTP GET request 连接时,这三个都给出 bad URL 错误。我避免使用 httr,因为它会安装 5 个额外的 dependencies,而我希望我的 R 程序中的依赖性最小。我不确定 httr 是否能够处理 URL.

中的这么多字符

有没有办法可以 encode/pack 达到允许的限制或更好的 approach/package 可以处理类似于 python 的任何长度的 URL urllib?

提前致谢。

这不是 RCurl 的限制。

让我们做一个长URL并尝试一下:

> s = paste0(rep(letters,2000),collapse="")
> nchar(s)
[1] 52000

这是A-Z的52000个字符。贴在 URL:

> url = paste0("http://www.omegahat.net/RCurl/",s,sep="")
> nchar(url)
[1] 52030
> substr(url, 1, 40)
[1] "http://www.omegahat.net/RCurl/abcdefghij"

现在尝试获取它:

> txt = getURL(url)
> txt
[1] "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\n<html><head>\n<title>414 Request-URI Too Large</title>\n</head><body>\n<h1>Request-URI Too Large</h1>\n<p>The requested URL's length exceeds the capacity\nlimit for this server.<br />\n</p>\n</body></html>\n"
> 

这是服务器的正确响应。服务器判定它是一个长 URL,返回 414 错误,并证明 RCurl 可以请求超过 40,000 个字符的 URLs。

在我们了解更多信息之前,我只能假设 "bad URL" 消息来自服务器,对此我们一无所知。