Rcurl with posting data using xml

大憨熊 提交于 2019-12-11 21:07:27

问题


I am trying to translate following curl command to Rcurl and am having trouble in posting the data using a file using RCURL

curl –X POST –d @out2 http://211.211.211.211:27844/ssentsvc --  header 'SOAPAction: "http://google.com"' --header 'Content-Type: text/xml'

above command works

I am trying the following in RCURL, any ideas on how to incorporate -d option in R curl for posting via a data file(xml file) ??

postForm('http://211.211.211.211:27844/ssentsvc' ,style='HTTPPOST',.opts=list(httpheader=c('SOAPAction'='"http://google.com"', 'Content-Type'='text/xml'),postfields=out2))

I tried a quick google search and could not find anything relevent. Please advise or direct mew to relevant pointers.


回答1:


Too long for a comment...

You could try something like this (using the httr package).

# this is just to create a file with xml content - you have this already
library(XML)
txt <- '<?xml version="1.0" encoding="UTF-8"?><doc><item>text</item><item>text</item><item>text</item></doc>'
out2 <- "myfile.xml"
saveXML(xmlTreeParse(txt,useInternalNodes=T),out2)

# you start here...
library(httr)
POST(url='http://211.211.211.211:27844/ssentsvc',
     body=upload_file(out2),
     config=add_headers(c('SOAPAction'='"http://google.com"', 'Content-Type'='text/xml')))


来源:https://stackoverflow.com/questions/24050773/rcurl-with-posting-data-using-xml

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!