问题
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