2016-11-24 67 views
0

我想将一些代码从RCurl移植到curl包,以查看是否有一些效率增益。R:使用卷曲包上传二进制文件

哪个是等价的:

library(RCurl) 
resp = postForm("https://httpbin.org/post", "fileData" = fileUpload(filename = "app.exe", contentType = "application/octet-stream"), 
     .opts = list(httpheader = c(Authorization = "token 123", `Content-Type` = "application/octet-stream"))) 

curl -H "Authorization: token 123" -H "Content-Type: application/octet-stream" --data-binary @app.exe "https://httpbin.org/post" 

使用curl包?

顺便说一句,这是我的尝试:

library(curl) 
h=new_handle() 
handle_setform(h, 
    c(Authorization = "token 123", `Content-Type` = "application/octet-stream"), 
    fileData = form_file("app.exe", type="application/octet-stream") 
) 
req=curl_fetch_memory("http://httpbin.org/post", handle = h) 
+0

这是一个工具的要求。请显示您尝试过的方式以及您卡住的位置。 –

回答

0

我需要进一步的测试,但是这似乎是一个普通的工作上传解决方案:

library(curl) 
h=new_handle() 
handle_setheaders(h, 
     Authorization = "token 123", 
     "Content-Type" = "application/x-dosexec" 
     ) 

handle_setform(h, 
       app = form_file("app.exe", type="application/x-dosexec")) 
req=curl_fetch_memory("http://httpbin.org/post", handle = h)