To make an httr SOAP API request using R, follow these steps:
httr
and XML
packages in R by using the following commands in R console:install.packages("httr")
install.packages("XML")
httr
and XML
packages in R.library(httr)
library(XML)
url <- "http://example.com/soap-api"
soap_body <- '<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<myFunctionRequest xmlns="http://example.com/">
<parameter1>value1</parameter1>
<parameter2>value2</parameter2>
</myFunctionRequest>
</soap:Body>
</soap:Envelope>'
Note: Replace the myFunctionRequest
and parameter1
, parameter2
with your desired function and parameters.
httr
package.response <- POST(url,
body = soap_body,
add_headers("Content-Type" = "text/xml;charset=UTF-8",
"SOAPAction" = "http://example.com/myFunction"),
verbose())
Note: Replace the "http://example.com/myFunction"
with your desired function.
response_content <- content(response, as = "text")
response_xml <- xmlParse(response_content)
result <- xpathApply(response_xml, "//myResult", xmlValue)
Note: Replace "//myResult"
with your desired result node.
print(result)
Your output will contain the required information from the SOAP API request.
Asked: 2021-06-11 11:00:00 +0000
Seen: 20 times
Last updated: Jul 30 '21