【发布时间】:2014-06-10 16:23:26
【问题描述】:
我想下载一个文件,但我必须使用 POST 发送变量才能执行此操作。现在我正在使用postForm 函数来发送变量,但我不知道如何下载文件。
postForm 返回如下内容:
doc <- postForm("http://gpwinfostrefa.pl/GPWIS2/pl/quotes/archive/3",
dateFrom="2014-05-10", dateTo = "2014-06-10",
instrumentType = "10", isin="PLOPTTC00011", style="post",
.opts=curlOptions(encoding="UTF-8", http.version=HTTP_VERSION_1_0))
> doc
[1] d0 cf 11 e0 a1 b1 1a e1 00 00 00 00 00 00 00 00 00 00 00 00 ...
attr(,"Content-Type") charset
"application/csv" "UTF-8"
> str(doc)
atomic [1:10752] d0 cf 11 e0 ...
- attr(*, "Content-Type")= Named chr [1:2] "application/csv" "UTF-8"
..- attr(*, "names")= chr [1:2] "" "charset"
但我不知道我是否可以用这个做点什么。是否可以(可能使用其他功能)同时下载文件发送变量。
(PS。该文件是 Excel 文件,即使 Content-Type 声明它是 csv)
【问题讨论】:
-
您是否尝试过将返回值写入文件?
cat(x, file="whatever")? -
所以,我尝试将值写入文件,但没有成功。该文件只是一个文本文件
0 cf 11 e0 a1 b1 ...(看起来像是用十六进制写的),我需要一个excel文件:/。也许有一种方法可以将此变量转换为excel,但我不知道如何。 -
给我们你用来做 POST 的代码。
-
doc <- postForm("http://gpwinfostrefa.pl/GPWIS2/pl/quotes/archive/3", dateFrom="2014-05-10", dateTo = "2014-06-10", instrumentType = "10", isin="PLOPTTC00011", style="post", .opts=curlOptions(encoding="UTF-8", http.version=HTTP_VERSION_1_0))