这不是RCurl的限制。
让我们做一个长的URL和尝试:
> s = paste0(rep(letters,2000),collapse="")
> nchar(s)
[1] 52000
这是A-Z的52000个字符。它贴在一个网址:
> 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个字符的URL。
直到我们知道更多,我只能假设“坏URL”消息来自服务器,我们什么都不知道。
从这些答案大约2000个字符看起来像一个最大值。请参阅以下相关问题:http://stackoverflow.com/questions/417142/what-is-the-maximum-length-of-a-url-in-different-browsers,http://stackoverflow.com/questions/2659952 /最大长度的-HTTP-GET请求。 – Dave2e
看着'jsonlite :: fromJSON',你会发现它检查'txt'(你的情况是一个URL)是不是'<1000“字节'(['jsonlite :: fromJSON' source code](https:// github.com/jeroenooms/jsonlite/blob/master/R/fromJSON.R)) – SymbolixAU
那么,除了将这个'GET'请求转换为'POST'请求之外,是否还有办法通过R访问长URL?我认为'HTTP'协议的全部目的是失败的? – user6591903