curl POST语句到RCurl或httr

curl POST语句到RCurl或httr,r,libcurl,rcurl,httr,R,Libcurl,Rcurl,Httr,我有一个工作声明,将一个文件发布到诺基亚的此处批量地理编码服务 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

我有一个工作声明,将一个文件发布到诺基亚的此处批量地理编码服务

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"))
库(RCurl)

url我不是诺基亚的开发者,我假设这些不是你真正的API信条。这将有助于您进一步了解
httr

url <- "http://batch.geocoder.cit.api.here.com/6.2/jobs"

a <- POST(url, encode="multipart",                      # this will set the header for you
          body=list(file=upload_file("example.txt")),   # this is how to upload files
          query=list(
            action="run",
            mailto="test@example.com",
            maxresults="1",
            language="es-ES",                           # this will build the query string
            header="true",
            indelim="|",
            outdelim="|",
            outcols="displayLatitude,displayLongitude", # i shortened this for the example
            outputCombined="false",
            app_code="APPCODE",
            app_id="APPID"), 
          verbose())                                    # this lets you verify what's going on

url这是基于hrbrmstr解决方案的解决方案

bod这让我非常接近。我收到一个错误的400请求。我想我缺少的是使用--data二进制参数提交有效负载的要求。诺基亚批处理地理编码器文档第20页。。。尝试使用
-v
(详细标志)运行curl,使用
verbose()
运行
httr::POST
,并比较输出。这将帮助您找出请求之间的区别。看起来我需要在httr中指定--data binary选项。有没有办法做到这一点?你需要弄清楚这个选项的作用。当使用--data选项上传数据时,换行符和回车符会被去掉。。。这对我来说是个问题。使用--data binary选项上载数据时,不会对文件进行任何处理。
url <- "http://batch.geocoder.cit.api.here.com/6.2/jobs"

a <- POST(url, encode="multipart",                      # this will set the header for you
          body=list(file=upload_file("example.txt")),   # this is how to upload files
          query=list(
            action="run",
            mailto="test@example.com",
            maxresults="1",
            language="es-ES",                           # this will build the query string
            header="true",
            indelim="|",
            outdelim="|",
            outcols="displayLatitude,displayLongitude", # i shortened this for the example
            outputCombined="false",
            app_code="APPCODE",
            app_id="APPID"), 
          verbose())                                    # this lets you verify what's going on