SOAP request in R
This solves the problem:
library(RCurl)
headerFields =
c(Accept = "text/xml",
Accept = "multipart/*",
'Content-Type' = "text/xml; charset=utf-8",
SOAPAction = "https://advertising.criteo.com/API/v201010/clientLogin")
body = '<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<clientLogin xmlns="https://advertising.criteo.com/API/v201010">
<username>string</username>
<password>string</password>
<source>string</source>
</clientLogin>
</soap:Body>
</soap:Envelope>'
curlPerform(url = "https://advertising.criteo.com/API/v201010/AdvertiserService.asmx",
httpheader = headerFields,
postfields = body
)
How to do a SOAP request for EUR-Lex API with R?
The answers you linked to have pretty good examples to work off of. Adding in the various URLs from the WSDL and information from the manual, you end up with the code below.
Unfortunately due to the EUR-Lex security restrictions I couldn't test this (you need a username and password from them, which I assume you have), but it should at the very least get you on the right track.
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
Soap request in R: POST not supported
The WSDL give the definition of the SOAP endpoint. That's not where you should be posting your request. In the content of the WSDL there is a <wsdlsoap:address location="">
attribute which appears to give the correct URL where you should send your post request. This version of the request seems towk work
library(RCurl)
xml.request = r'[<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" >
<soapenv:Header/>
<soapenv:Body>
<urn:checkVat xmlns:urn="urn:ec.europa.eu:taxud:vies:services:checkVat:types">
<urn:countryCode>NL</urn:countryCode>
<urn:vatNumber>800938495B01</urn:vatNumber>
</urn:checkVat>
</soapenv:Body>
</soapenv:Envelope>]'
myheader=c(Connection="close",
'Content-Type' = "text/xml",
Accept = "text/xml")
getURL(url = "http://ec.europa.eu/taxation_customs/vies/services/checkVatTestService",
postfields=xml.request,
httpheader=myheader,
verbose=TRUE)
# [1] "<env:Envelope xmlns:env=\"http://schemas.xmlsoap.org/soap/envelope/\">
# <env:Header/><env:Body><ns2:checkVatResponse
# xmlns:ns2=\"urn:ec.europa.eu:taxud:vies:services:checkVat:types\">
# <ns2:countryCode>NL</ns2:countryCode>
# <ns2:vatNumber>800938495B01</ns2:vatNumber><ns2:requestDate>2022-08-
# 29+02:00</ns2:requestDate><ns2:valid>false</ns2:valid><ns2:name></ns2:name>
# <ns2:address></ns2:address></ns2:checkVatResponse></env:Body></env:Envelope>"
How to convert SOAP request curl to RCurl
Here's how with httr:
library(httr)
r <- POST("http://www.sample.com/soap", body = upload_file("request.xml"))
stop_for_status(r)
content(r)
Related Topics
Rjava Linker Error Licuuc with Anaconda & Fopenmp Error Without Anaconda for MACos Sierra 10.12.4
Substitute Dt1.X with Dt2.Y When Dt1.X and Dt2.X Match in R
Split Character Columns and Get Names of Field in String
Best Practice: Should I Try to Change to Utf-8 as Locale or Is It Safe to Leave It as Is
Given Value of Matrix, Getting It's Coordinate
Why Does Rm Inside a Function Not Delete Objects
Find All Positions of All Matches of One Vector of Values in Second Vector
Loess Regression on Each Group with Dplyr::Group_By()
Importing Excel File Using Url Using Read.Xls
As.Numeric() Removes Decimal Places in R, How to Change
Finding Overlapping Ranges Between Two Interval Data
How to Get All Possible Subsets of a Character Vector in R