sách gpt4 ăn đã đi

r - 发送数据时使用POST下载R中的文件

In lại Tác giả: Walker 123 更新时间:2023-12-01 00:45:23 28 4
mua khóa gpt4 giày nike

我尝试下载一个文件,从我需要同时发送数据的服务器获取它。在命令行上使用 curl 可以正常工作:

curl "https://www.ishares.com/us/product-screener-download.dl" --data "productView=ishares&portfolios=239561-239855"

不幸的是,我没有让它与 R 一起工作。我尝试使用 download.file、download.file 和 libcurl、curl_download 和 httr。 (带有 curl 或 wget 的 download.file 不起作用,因为我在窗口机器上。)

我尝试过但对 curl 不起作用的内容:
library("curl")
handle <- new_handle()
handle_setopt(handle, customrequest = "POST")
handle_setform(handle, productView="ishares",portfolios="239561-239855")
curl_download("https://www.ishares.com/us/products/etf-product-list", "./data/ishares-us-etf.xls", handle=handle)

我尝试过但对 httr 不起作用的内容:
library(httr)
POST("https://www.ishares.com/us/products/etf-product-list", body = list(productView="ishares",portfolios="239561-239855"))

câu trả lời hay nhất

所以你应该使用正确的 URL 和 encode = "form"hiện hữu httr::POST() .
httr基于@leo 答案的解决方案:

library(httr)
POST("https://www.ishares.com/us/product-screener-download.dl",
body = list(productView = "ishares", portfolios = "239561-239855"),
encode = "form", write_disk("/tmp/ishares-us-etf.xls"))
#> Response [https://www.ishares.com/us/product-screener-download.dl]
#> Date: 2016-02-08 06:52
#> Status: 200
#> Content-Type: application/vnd.ms-excel;charset=UTF-8
#> Size: 13.6 kB
#> /tmp/ishares-us-etf.xls
head(readLines(file_path), 5)
#> [1] ""
#> [2] ""
#> [3] ""
#> [4] "
Xem sitemap của VNExpress