2015-11-04 22 views
0

我使用命令行工具捲曲發佈的數據,並從服務器的響應,該命令是這樣的:基於R完整-X 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") 
+1

你可能想從這篇文章中刪除實際的ID和密鑰。 – DunderChief

+0

@DunderChief,謝謝。 –

回答

2

隨着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")) 
+0

我認爲可能需要一個名爲'body = upload_file(「gpslog.gpx」)'和'accept_json()'可能比'Accept'更容易。無論哪種方式+1(我一直想寫'curl'命令行解碼器到R'httr'或R'curl',因爲這些都出現了這麼多。) – hrbrmstr

+0

編輯好點 – sckott

+0

感謝您的輸入,按我的想象工作。 –