无法在R中存储Web服务响应

时间:2017-12-20 17:11:42

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

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

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 Service Response

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

Value of object stored in R

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

1 个答案:

答案 0 :(得分:0)

您需要使用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()