【发布时间】:2014-10-28 14:46:47
【问题描述】:
我有这个工作 curl 语句可以将文件发布到诺基亚的 HERE 批量地理编码服务...
curl -X POST -H 'Content-Type: multipart/form-data;boundary=----------------------------4ebf00fbcf09' \
--data-binary @example.txt \
'http://batch.geocoder.cit.api.here.com/6.2/jobs?action=run&mailto=test@gmail.com&maxresults=1&language=es-ES&header=true&indelim=|&outdelim=|&outcols=displayLatitude,displayLongitude,houseNumber,street,district,city,postalCode,county,state,country,matchLevel,relevance&outputCombined=false&app_code=AJKnXv84fjrb0KIHawS0Tg&app_id=DemoAppId01082013GAL'
我试过这个:
library(RCurl)
url <- "http://batch.geocoder.cit.api.here.com/6.2/jobs? action=run&mailto=test@gmail.com&maxresults=1&language=es-ES&header=true&indelim=|&outdelim=|&outcols=displayLatitude,displayLongitude,houseNumber,street,district,city,postalCode,county,state,country,matchLevel,relevance&outputCombined=false&app_code=AJKnXv84fjrb0KIHawS0Tg&app_id=DemoAppId01082013GAL'"
postForm(url, file=fileUpload(filename="example.txt",
contentType="multipart/form-data;boundary=----------------------------4ebf00fbcf09"))
还有这个:
library(httr)
a <- POST(url, body=upload_file("example.txt", type="text/plain"),
config=c(add_headers("multipart/form-data;boundary=----------------------------4ebf00fbcf09")))
content(a)
将此文件用作example.txt:https://gist.github.com/corynissen/4f30378f11a5e51ad9ad
有没有办法在 R 中实现这个属性?
【问题讨论】:
-
尝试使用
-v(详细标志)和httr::POST使用verbose()运行curl 并比较输出。这将帮助您找出请求之间的不同之处。 -
看来我需要在 httr 中指定 --data-binary 选项。有没有办法做到这一点?
-
您需要弄清楚该选项的作用。
-
当使用 --data 选项上传数据时,换行符和回车符被删除......这对我来说是个问题。使用 --data-binary 选项上传数据时,不会对文件进行任何处理。