【问题标题】:Unable to store Web Service response in R无法在 R 中存储 Web 服务响应
【发布时间】:2017-12-20 17:11:41
【问题描述】:

我有一个 SOAP 请求,它在 Rstudio 中得到了正确的响应,如下面的屏幕截图所示。用于请求响应的代码是

library(RCurl)

headerFields = 
  c(Accept = "text/xml",
    'Content-Type' = "text/xml; charset=utf-8",
    SOAPAction = "")

body = '<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sch="http://www.xxxxx.com/esotservice/schema">
   <S:Header/>
<S:Body>
<sch:OwnerOnlyInquiryRequest>
<sch:RequestHeader>
<sch:ClientSystem>ePRS</sch:ClientSystem>
</sch:RequestHeader>
<sch:RequestParameterList>
<sch:RequestParam>12174391</sch:RequestParam>
</sch:RequestParameterList>
<sch:RequestType>CESEID</sch:RequestType>
<sch:PeckingOrder>Pricing</sch:PeckingOrder>
<sch:ViewType>Pricing</sch:ViewType>
</sch:OwnerOnlyInquiryRequest>
</S:Body>
</S:Envelope>'

R <- curlPerform(url = "http://slsesotdevt1.ute.xxxx.com:10149/esot/esotservice.wsdl",
            httpheader = headerFields,
            postfields = body, verbose=TRUE)

我在 RStudio 中得到的响应是

我的目的是将 web 服务响应(图像中的黑色文本)存储到代码中名为 R 的对象中,对象类为 XML,以便我可以使用 XML 包进一步处理数据。但是,当我说 print(R) 时,我得到的唯一回应是

在网上搜索后,响应 0 表示一切正常。但是有没有办法将响应实际存储在 R 中?如果我复制粘贴 Rstudio 中第一张图像中出现的黑色文本并将其提供给 xmlTreeParse 等 xml 函数,它会得到正确处理。

【问题讨论】:

    标签: r xml web-services xml-parsing rcurl


    【解决方案1】:

    您需要使用 basicTextGatherer 获取响应正文。

    例如(取自https://cran.r-project.org/web/packages/RCurl/RCurl.pdf):

    library(RCurl)
    
    headerFields = 
      c(Accept = "text/xml",
        'Content-Type' = "text/xml; charset=utf-8",
        SOAPAction = "")
    
    body = '<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sch="http://www.xxxxx.com/esotservice/schema">
       <S:Header/>
    <S:Body>
    <sch:OwnerOnlyInquiryRequest>
    <sch:RequestHeader>
    <sch:ClientSystem>ePRS</sch:ClientSystem>
    </sch:RequestHeader>
    <sch:RequestParameterList>
    <sch:RequestParam>12174391</sch:RequestParam>
    </sch:RequestParameterList>
    <sch:RequestType>CESEID</sch:RequestType>
    <sch:PeckingOrder>Pricing</sch:PeckingOrder>
    <sch:ViewType>Pricing</sch:ViewType>
    </sch:OwnerOnlyInquiryRequest>
    </S:Body>
    </S:Envelope>'
    
    h = basicTextGatherer()
    R <- curlPerform(url = "http://slsesotdevt1.ute.xxxx.com:10149/esot/esotservice.wsdl",
                httpheader = headerFields,
                postfields = body, verbose=TRUE,
    writefunction = h$update)
    body <- h$value()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-11-14
      • 1970-01-01
      • 2015-07-18
      • 2012-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-23
      • 1970-01-01
      相关资源
      最近更新 更多