卷曲中的RCurl相当于-H和--data-binary

时间:2014-02-25 12:09:56

标签: r post curl rcurl

如何将使用curl发送的POST请求转换为等效的RCurl命令?

curl 'http://www.example.com/example' -H 'Origin: http://www.example.com' -H 'Content-Type: text/xml;charset=utf-8' --data-binary '<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Header><clsSoapHeader xmlns="http://www.example.com/example"></clsSoapHeader></soap:Header><soap:Body><example-tag></example-tag></soap:Body></soap:Envelope>'

1 个答案:

答案 0 :(得分:1)

基于@Thomas的建议,这是我找到的解决方案

        h <- basicTextGatherer()
        url <- 'http://www.example.com/example'
        body <- '<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Header><clsSoapHeader xmlns="http://www.example.com/example"></clsSoapHeader></soap:Header><soap:Body><example-tag></example-tag></soap:Body></soap:Envelope>'
        curlPerform(url = url, httpheader=c(Accept="text/xml", Accept="multipart/*", 'Content-Type' = "text/xml; charset=utf-8"), postfields=body, writefunction = h$update, verbose = TRUE)

然后,可以通过h$update()

访问结果