如何将此curl命令转换为R curl调用? [英] How translate this curl command into a R curl call?

查看:120
本文介绍了如何将此curl命令转换为R curl调用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个curl命令,可以用bash调用

I have this curl command that I can call in bash

curl -X POST -H 'Content-Type: text/csv' --data-binary @data/data.csv https://some.url.com/invocations > data/churn_scored.jsonl

将CSV文件发布到API端点,然后将结果重定向到 .jsonl 文件。

which posts a CSV file to the API endpoint and I redirect the results into a .jsonl file.

我找不到可以在其中指定要发布到端点的数据文件的地方,例如使用curl的 @

I can't find where I can specify a data file to POST to the endpoint like using curl's @.

使用R的curl包(或任何其他包)实现CURL发布的方式是什么? ?我可以用另一种方式找出输出的重定向。

What's the way to achieve the CURL post using R's curl package (or any other package)? The redirection of output I can figure out in another way.

推荐答案

这是将curl命令转换为其他语言的非常有用的站点: https://curl.trillworks.com/#r

This is a very helpful site in converting curl commands to other languages: https://curl.trillworks.com/#r

在插入curl命令时,我得到了。

When plugging in your curl command there I got this.

require(httr)

headers = c(
  `Content-Type` = 'text/csv'
)

data = upload_file('data/data.csv')
res <- httr::POST(url = 'https://some.url.com/invocations', httr::add_headers(.headers=headers), body = data)

这篇关于如何将此curl命令转换为R curl调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆