如何使用 R 对 EUR-Lex API 进行 SOAP 请求?
How to do a SOAP request for EUR-Lex API with R?
您如何使用 R 为 EUR-Lex 的 API 请求 SOAP
?
EUR-Lex 是一个包含许多法律行为的欧盟数据库。在他们的网络服务手册中,他们描述了他们的 SOAP
系统,但没有描述如何使用 R。我已经尝试使用 httr
和 RCurl
一段时间了,但没有成功。我想使用 R 而不是 SOAPUI。
这里有人有这方面的经验吗?
根据下面的link,我是不是应该这样定义正文?
body <- "<sear:searchRequest>
<sear:expertQuery>${expert query}</sear:expertQuery> <sear:page>${page}</sear:page>
<sear:pageSize>${pageSize}</sear:pageSize> <sear:searchLanguage>${search language
</sear:searchLanguage>
</sear:searchRequest>"
然后如何将其与 headerfields
结合使用 RCurl
或 httr
包?
以下三个答案似乎相关,但我不知道如何将它们应用到我的 EUR-Lex 示例中:
- How to convert SOAP request curl to RCurl
- SOAP Client with WSDL for R
- SOAP request in R
EUR-Lex API links:
您链接到的答案有很好的例子可供参考。添加来自 WSDL 的各种 URL 和来自手册的信息,您最终得到以下代码。
不幸的是,由于 EUR-Lex 安全限制,我无法对此进行测试(你需要他们提供的用户名和密码,我假设你有),但它至少应该让你走上正轨.
library(RCurl)
headerFields =
c(Accept = "text/xml",
Accept = "multipart/*",
'Content-Type' = "text/xml; charset=utf-8",
SOAPAction = "https://eur-lex.europa.eu/EURLexWebService/doQuery")
body = '<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:sear="http://eur-lex.europa.eu/search">
<soap:Header>
<wsse:Security soap:mustUnderstand="true" xmlns:wsse="http://docs.oasisopen.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken wsu:Id="UsernameToken-3" xmlns:wsu="http://docs.oasisopen.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:Username>${EUR-Lex username}</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-
wss-username-token-profile-1.0#PasswordText">${WS password}</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</soap:Header>
<soap:Body>
<sear:searchRequest>
<sear:expertQuery>${expert query}</sear:expertQuery>
<sear:page>${page}</sear:page>
<sear:pageSize>${pageSize}</sear:pageSize>
<sear:searchLanguage>${search language}</sear:searchLanguage>
</sear:searchRequest>
</soap:Body>
</soap:Envelope>'
reader = basicTextGatherer()
curlPerform(url = "https://eur-lex.europa.eu/EURLexWebService",
httpheader = headerFields,
postfields = body,
writefunction = reader$update
)
xml <- reader$value()
xml
您如何使用 R 为 EUR-Lex 的 API 请求 SOAP
?
EUR-Lex 是一个包含许多法律行为的欧盟数据库。在他们的网络服务手册中,他们描述了他们的 SOAP
系统,但没有描述如何使用 R。我已经尝试使用 httr
和 RCurl
一段时间了,但没有成功。我想使用 R 而不是 SOAPUI。
这里有人有这方面的经验吗?
根据下面的link,我是不是应该这样定义正文?
body <- "<sear:searchRequest>
<sear:expertQuery>${expert query}</sear:expertQuery> <sear:page>${page}</sear:page>
<sear:pageSize>${pageSize}</sear:pageSize> <sear:searchLanguage>${search language
</sear:searchLanguage>
</sear:searchRequest>"
然后如何将其与 headerfields
结合使用 RCurl
或 httr
包?
以下三个答案似乎相关,但我不知道如何将它们应用到我的 EUR-Lex 示例中:
- How to convert SOAP request curl to RCurl
- SOAP Client with WSDL for R
- SOAP request in R
EUR-Lex API links:
您链接到的答案有很好的例子可供参考。添加来自 WSDL 的各种 URL 和来自手册的信息,您最终得到以下代码。
不幸的是,由于 EUR-Lex 安全限制,我无法对此进行测试(你需要他们提供的用户名和密码,我假设你有),但它至少应该让你走上正轨.
library(RCurl)
headerFields =
c(Accept = "text/xml",
Accept = "multipart/*",
'Content-Type' = "text/xml; charset=utf-8",
SOAPAction = "https://eur-lex.europa.eu/EURLexWebService/doQuery")
body = '<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:sear="http://eur-lex.europa.eu/search">
<soap:Header>
<wsse:Security soap:mustUnderstand="true" xmlns:wsse="http://docs.oasisopen.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken wsu:Id="UsernameToken-3" xmlns:wsu="http://docs.oasisopen.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:Username>${EUR-Lex username}</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-
wss-username-token-profile-1.0#PasswordText">${WS password}</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</soap:Header>
<soap:Body>
<sear:searchRequest>
<sear:expertQuery>${expert query}</sear:expertQuery>
<sear:page>${page}</sear:page>
<sear:pageSize>${pageSize}</sear:pageSize>
<sear:searchLanguage>${search language}</sear:searchLanguage>
</sear:searchRequest>
</soap:Body>
</soap:Envelope>'
reader = basicTextGatherer()
curlPerform(url = "https://eur-lex.europa.eu/EURLexWebService",
httpheader = headerFields,
postfields = body,
writefunction = reader$update
)
xml <- reader$value()
xml