r - 使用 r 中的 curl 为 DVLA MOT 数据制作 curl 命令
问题描述
尝试使用 curl 包在 r 中编写 curl 命令时,我感到非常迷茫。
我拥有的 curl 命令是
curl -H "Accept: application/json+v3" -H "x-api-key: XXXXX" \https://beta.check-mot.service.gov.uk/trade/vehicles/mot-tests\?page=[0-58002]
我试过以下
library(curl)
h <- new_handle()
handle_setopt(h);
handle_setheaders(h,
'page'='[0-58002]',
'Accept' = 'application/json',
'x-api-key' = 'XXXXX'
)
tmp <- tempfile()
curl_download("https://beta.check-mot.service.gov.uk/trade/vehicles/mot-tests", destfile = tmp, handle = h)
但这似乎不起作用。我究竟做错了什么?我知道最初的 curl 命令有效,而不是 r 版本。
解决方案
我想你想要
library(curl)
h <- new_handle()
handle_setopt(h, verbose = TRUE)
handle_setheaders(h, .list = list(
'Accept' = 'application/json',
'x-api-key' = 'XXXXX')
)
tmp <- tempfile()
curl_download("https://beta.check-mot.service.gov.uk/trade/vehicles/mot-tests?page=[0-58002]", destfile = tmp, handle = h)
handle_setopt(h, verbose = TRUE)
获得详细的 curl 输出,将帮助您调试任何问题。查询参数在 url 中,而不是在标题中
推荐阅读
- react-native - 已解决反应导航不起作用反应本机
- go - chromedp fails to start a new instance of chrome
- html - 动画 svg 渐变设置为背景图像
- javascript - 根据条件和索引从数组中删除元素
- angular - TS 和 HTML 之间的 FormGroup 绑定
- java - 创建谓词以将实体与 Map 属性中的条目匹配
- ssl - Nginx 代理传递给反向代理
- opencv - 使用 Rect 对象绘制矩形的最小打开 cv 版本是什么
- python - 使用 scikit learn 可视化我的特殊 SVC 模型的决策边界(边界)
- python - 为什么“png”格式在决策树 Python 中无法识别?