【问题标题】:Rcurl with posting data using xml使用 xml 发布数据的 Rcurl
【发布时间】:2014-06-06 11:45:28
【问题描述】:

我正在尝试将以下 curl 命令转换为 Rcurl,但在使用 RCURL 使用文件发布数据时遇到问题

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

以上命令有效

我正在 RCURL 中尝试以下内容,关于如何在 R curl 中合并 -d 选项以通过数据文件(xml 文件)发布的任何想法??

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

我尝试了快速谷歌搜索,但找不到任何相关内容。请告知或指导mew相关指针。

【问题讨论】:

    标签: r curl rcurl


    【解决方案1】:

    评论太长了...

    您可以尝试这样的事情(使用httr 包)。

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

    【讨论】:

    • 你可以稍微简化一下post调用:POST('http://211.211.211.211:27844/ssentsvc', body = upload_file(out2), add_headers(SOAPAction = "http://google.com", 'Content-Type' = 'text/xml'))
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-26
    • 2011-01-05
    • 2011-05-18
    • 1970-01-01
    相关资源
    最近更新 更多