在命令行工具curl中使用R complete-X POST
我使用命令行工具curl发布数据并从服务器获取响应,命令如下:在命令行工具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 -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
命令行解码器到Rhttr
或Rcurl
,因为它们出现得太多了。)