I'd like to get a SOAP response from https://ec.europa.eu/taxation_customs/vies/checkVatTestService.wsdl, using the below example XML request:
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' = "application/xml",
'Content-length' =nchar(xml.request),
Accept = "multipart/*",
Accept = "text/xml")
data = getURL(url = "https://ec.europa.eu/taxation_customs/vies/checkVatTestService.wsdl",
postfields=xml.request,
httpheader=myheader,
verbose=TRUE)
I am getting this error, thanks for any help:
* Trying 2a01:7080:14:100::666:30:443...
* Connected to ec.europa.eu (2a01:7080:14:100::666:30) port 443 (#0)
* schannel: disabled automatic use of client certificate
* schannel: added 155 certificate(s) from CA file 'C:/Users/XX/AppData/Local/R/win-library/4.2/RCurl/etc/ca-bundle.crt'
* schannel: connection hostname (ec.europa.eu) did not match against certificate name (*.ec.europa.eu)
* schannel: connection hostname (ec.europa.eu) validated against certificate name (ec.europa.eu)
> POST /taxation_customs/vies/checkVatTestService.wsdl HTTP/1.1
Host: ec.europa.eu
Connection: close
Content-Type: application/xml
Content-length: 379
Accept: multipart/*
Accept: text/xml
* Mark bundle as not supporting multiuse
< HTTP/1.1 405 Method Not Allowed
< Cache-Control: no-store
< Date: Mon, 29 Aug 2022 16:38:23 GMT
< Content-Length: 43
< Content-Type: text/html; charset=UTF-8
< Allow: GET, HEAD
< X-Content-Type-Options: nosniff
< X-Frame-Options: DENY
< Server: Europa
< Connection: close
<
* Closing connection 0
* schannel: shutting down SSL/TLS connection with ec.europa.eu port 443
EDIT: Second method:
r <- POST("https://ec.europa.eu/taxation_customs/vies/checkVatTestService.wsdl", body = body)
stop_for_status(r)
Error: Method Not Allowed (HTTP 405).
content(r)
[1] <body><p>Request method 'POST' not supported</p></body>
CodePudding user response:
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>"