2014-02-25 68 views
1

如何將使用curl發送的POST請求轉換爲等效的RCurl命令?RCurl等效於-H和--data-binary捲曲

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>'

+2

RCurl訪問使用libcurl的,而不是命令 - 行,所以相關的[參考文檔在這裏](http://curl.haxx.se/libcurl/c/curl_easy_setopt.html)。您可以直接在'curlPerform'調用中直接使用任何'curl_easy_setopt'選項。 – Thomas

回答

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()