Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在命令行工具curl中使用R complete-X POST_R_Curl_Rcurl - Fatal编程技术网

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

在命令行工具curl中使用R complete-X POST,r,curl,rcurl,R,Curl,Rcurl,我使用命令行工具curl发布数据并从服务器获取响应,命令如下: 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

我使用命令行工具curl发布数据并从服务器获取响应,命令如下:

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"))

url您可能希望从此帖子中删除实际的ID和密钥。@DunderChief,谢谢。我想这可能需要一个名为
body=upload\u的文件(“gpslog.gpx”)
accept\u json()
可能比
accept
更容易。无论哪种方式+1(我一直想写一个
curl
命令行解码器到R
httr
或R
curl
,因为它们出现得太多了。)