简体   繁体   English

通过POST请求发送压缩数据

[英]Sending gzipped data via a POST request

I am trying to encode a list as JSON, compress it using gzip in Rcompression, and send it to a server using a POST request in RCurl. 我正在尝试将列表编码为JSON,在Rcompression中使用gzip对其进行压缩,然后使用RCurl中的POST请求将其发送到服务器。

# COMPRESS THE REQUEST
all <- list(this=1,is=2,a=3,list=4)
json <- toJSON(all)
gzip <- gzip(json)

# SEND IT TO THE SERVER
status <- postForm(SERVER_URI,data=fileUpload(contents=gzip,contentType="application/x-gzip"),style="HTTPPOST",binary=TRUE)

However, when I try to POST the data to the server, I get the following error: 但是,当我尝试将数据发布到服务器时,出现以下错误:

Error in postForm(SERVER_URI, data = gzip) : 
  STRING_ELT() can only be applied to a 'character vector', not a 'raw'

I understand that the gzip data is in raw format and the postForm function does not like that, but I'm unclear how to resolve the issue to send the raw data to the server via a POST request. 我知道gzip数据是原始格式,而postForm函数不喜欢这种格式,但是我不清楚如何解决通过POST请求将原始数据发送到服务器的问题。

The official paper for RCurl states that POSTing binary data has not yet been implemented, and is listed in the document under "Future Work". RCurl的官方文件指出,尚未执行POST二进制数据的发布,该文件在“ Future Work”下的文档中列出。 So, maybe there's no solution for this yet in RCurl since the document was published. 因此,自文档发布以来,RCurl中可能还没有解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM