在命令行工具 curl 中使用 R complete -X POST

Using R complete -X POST in command line tool curl

我使用命令行工具 curl 到 post 数据并从服务器获取响应,命令是这样的:

curl -X POST -H 'Content-Type: application/gpx+xml' -H 'Accept: application/json' --data-binary @gpslog.gpx "http://test.roadmatching.com/rest/mapmatch/?app_id=MY_APPID&app_key=MY_APPKEY" -o output.json

我尝试使用 RCurl 包来做同样的事情,但它不起作用。有人能指出我正确的方向吗?谢谢

postForm(uri = "http://test.roadmatching.com/rest/mapmatch/?app_id=MYID&app_key=MYKEY",
    .ops = list(httpheader = c('Content-type': 'application/gpx','Accept': 'application/json')),
    .params = "/Users/data.gpx")

使用 httr - 未经测试,您可能需要稍微调整一下

url <- "http://test.roadmatching.com/rest/mapmatch"
args <- list(app_id = "MY_APPID", app_key = "MY_APPKEY")
gpxxml <- add_headers(`Content-Type` = "application/gpx+xml")
httr::POST(url, query = args, gpxxml, accept_json(), 
           write_disk("output.json"), body = upload_file("gpslog.gpx"))