Check VAT Number at VIES with classic ASP + SOAP - soap

I'm trying to check European VAT Number at VIES via Webservice:
with my poor knowledge I built the following routine:
<%
strEnvelope="<soapenv:Envelope xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:urn=""urn:ec.europa.eu:taxud:vies:services:checkVat:types"">"
strEnvelope=strEnvelope&"<soapenv:Header/>"
strEnvelope=strEnvelope&"<soapenv:Body>"
strEnvelope=strEnvelope&"<urn:checkVat>"
strEnvelope=strEnvelope&"<urn:countryCode>DE</urn:countryCode>"
strEnvelope=strEnvelope&"<urn:vatNumber>247856515</urn:vatNumber>"
strEnvelope=strEnvelope&"</urn:checkVat>"
strEnvelope=strEnvelope&"</soapenv:Body>"
strEnvelope=strEnvelope&"</soapenv:Envelope>"
set objHTTP = Server.CreateObject("MSXML2.ServerXMLHTTP.6.0")
objHTTP.open "post", "http://ec.europa.eu/taxation_customs/vies/services/checkVatService"
objHTTP.setRequestHeader "Content-Type", "text/xml"
objHTTP.setRequestHeader "SOAPMethodName", "checkVat"
objHTTP.send strEnvelope
strReturn = objHTTP.responseBody
response.write strReturn
%>
but I got this answer
猼慯㩰湅敶潬数ç æ±­ç®çŒºæ…¯ãµ°æ ¢ç‘´ã©°â¼¯æ³æ•¨æ…­â¹³æµ¸ç¬æ…¯â¹°ç‰¯â½§æ½³ç¡æ”¯ç™®æ±¥ç¯â½¥ã¸¢çŒ¼æ…¯ã©°æ½‚祤㰾档æ¥å™«ç‘¡æ•’ç³æ¹¯æ•³ç æ±­ç®âˆ½ç‰µã©®æ¥æ”®ç‰µç¯â¹¡ç•¥çºç¡¡æ‘µç˜ºæ•©ã©³æ•³ç™²æ©ç¥æŒºæ•¨æ­£æ…–㩴祴数≳㰾潣湵牴ä¹æ‘¯ã¹¥ä•„⼼潣湵牴ä¹æ‘¯ã¹¥ç˜¼ç‘¡ç•Žæ‰­ç‰¥ãˆ¾ãœ´ã”¸ã”¶ã”±â¼¼æ…¶ä¹´æµµæ•¢ã¹²çˆ¼ç…¥æ•µç‘³æ…„整㈾㄰ⴷ㜰ㄭ⬵㈰〺㰰爯煥敵瑳慄整㰾慶楬㹤牴敵⼼慶楬㹤渼浡㹥ⴭ㰭港浡㹥愼摤敲ç³â´¾â´­â¼¼æ‘¡ç‰¤ç¥ã¹³â¼¼æ¡£æ¥å™«ç‘¡æ•’ç³æ¹¯æ•³ã°¾çŒ¯æ…¯ã©°æ½‚祤㰾猯慯㩰湅敶潬数> 猼慯㩰湅敶潬数ç æ±­çÂ®çŒºæ…¯ãµ°æ ¢ç‘´ã©°â¼¯æ³敨慭⹳浸ç¬慯⹰牯⽧潳ç¡æâ€Â¯Ã§â„¢Â®Ã¦Â±Â¥Ã§Â¯â½¥ã¸¢çŒ¼æ…¯ã©°æ½‚祤㰾档æ¥噫瑡敒ç³湯敳ç æ±­ç®∽牵㩮æÂ¥æâ€Â®Ã§â€°ÂµÃ§Â¯â¹¡ç•¥çº硡摵瘺敩㩳敳癲æ©ç¥挺敨正慖㩴祴数≳㰾潣湵牴ä¹摯㹥䕄⼼潣湵牴ä¹摯㹥瘼瑡畎扭牥㈾㜴ãâ€Â¸Ã£â€Â¶Ã£â€Â±Ã¢Â¼Â¼Ã¦â€¦Â¶Ã¤Â¹Â´Ã¦ÂµÂµÃ¦â€¢Â¢Ã£Â¹Â²Ã§Ë†Â¼Ã§â€¦Â¥Ã¦â€¢ÂµÃ§â€˜Â³Ã¦â€¦â€žÃ¦â€¢Â´Ã£Ë†Â¾Ã£â€žÂ°Ã¢Â´Â·Ã£Å“°ã„­â¬µãˆ°ã€ºã°°çˆ¯ç…¥æ•µç‘³æ…„整㰾慶楬㹤牴敵⼼慶楬㹤渼浡㹥ⴭ㰭港浡㹥愼摤敲ç³ⴾⴭ⼼摡牤ç¥㹳⼼档æ¥噫瑡敒ç³湯敳㰾猯慯㩰潂祤㰾猯慯㩰湅敶潬数>
can give some hints?
Thanks

The text representation of the response is in the responseText property, so:
strReturn = objHTTP.responseText

Related

Run-time error with http setRequestHeader

Public Function WebRequest(url As String, sVal1 As String, sVal2 As Integer) As String
Dim xmlhttp As MSXML2.xmlhttp
Set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP")
xmlhttp.setRequestHeader "Content-Type", "application/json"
'xmlhttp.setRequestHeader "Accept", "text/xml"
'xmlhttp.setRequestHeader "Value1", sVal1
'xmlhttp.setRequestHeader "Value2", sVal2
xmlhttp.open "GET", url, False
xmlhttp.send
WebRequest = xmlhttp.responseText
Set xmlhttp = Nothing
End Function
When I run this function, even with the other paramaters commented out, it fails at the line: xmlhttp.setRequestHeader "Content-Type", "application/json" no matter what I put into the request header fields.
I get the error: Run-time error '-2147467259(80004005)' Unspecified error if I comment out the setRequestHeader line then it works fine, but the API returns that I am missing header fields (expected) I have ried MS XML v3.0 and v6.0 and am completely out of ideas...
Set your request headers after opening the request.

VBScript HTTP - how to read DOM element value and have server reply correctly

I'm having lots of trouble with a VBScript that I'm putting together that, when executed, automatically logs into a webpage. The problem I'm facing at the moment is that my POST doesn't mimic correctly the same as the browser does. Any help is greatly appreciated!
EDIT1: I found a sloppy way to read the DOM element value, but even then there is something wrong with my POST because it differs from that of the browser.
EDIT2: Helen's answer steered me in the right direction, now it works perfectly.
This is the code:
Dim URL
URL = "http://192.168.0.10/login.php"
Dim http : Set http = CreateObject("Msxml2.ServerXMLHTTP.6.0")
http.Open "GET", URL, FALSE
http.Send
Dim html : Set html = CreateObject("HTMLFILE")
html.write http.responseText
' Getting the DOM element's value by it's name
Dim rnd : rnd = html.getElementsByName("rnd").[0].value
'WScript.Echo rnd
sRequest = "username=admin&password=admin&rnd=" & rnd
'Msgbox sRequest, 0, "Final sRequest"
SetCookie = http.getResponseHeader("Set-Cookie")
'Bellow I trim an unnecessary part of the cookie (; path=/;) to keep only the AuthID
SetCookie = Left(SetCookie, Len(SetCookie) - 9)
'Msgbox SetCookie, 0, "Cookie Value"
Set http = nothing
http.Open "POST", URL, False
http.setRequestHeader "Host", "192.168.0.10"
http.setRequestHeader "Content-Length", Len(sRequest)
http.setRequestHeader "Cache-Control", "max-age=0"
http.setRequestHeader "Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"
http.setRequestHeader "Origin", "http://192.168.0.10"
http.setRequestHeader "User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.137 Safari/537.36"
http.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
http.setRequestHeader "Referer", "http://192.168.0.10/login.php"
http.setRequestHeader "Accept-Encoding", "gzip,deflate,sdch"
http.setRequestHeader "Accept-Language", "en-US;q=0.6,en;q=0.4"
http.setRequestHeader "Cookie", SetCookie
'Msgbox SetCookie, 0, "Cookie Value"
http.Send sRequest
'Msgbox sRequest, 0, "Final sRequest"
'HTTPGet = http.responseText
Set http = nothing
Thanks again Helen! )
Is this random DOM element on the http://192.168.0.10/login.php page? You could GET the page source and load it into an HTMLFILE object. Then you'll be able to extract the needed element, e.g. using getElementById:
http.Open "GET", "httpp://192.168.0.10/login.php", False
http.Send
Dim html : Set html = CreateObject("HTMLFILE")
html.write http.responseText
Dim rnd : rnd = html.getElementsByName("rnd").[0].value ' Replace with your element query
WScript.Echo rnd

Current date / time to RFC 2822 date function with vb / classic asp

I am trying to write a script to push data out to an amazon s3 bucket and I need to generate what I believe is an RFC 2822 date to send in the header request.
The date looks like this "Tue, 12 June 2012 23:41:58 +0000"
I just need a function to generate the correct time format as I am getting the following error.
RequestTimeTooSkewed The difference between the request time and the current time is too large.
This is what I have so far...
<%
sTimeStamp = "Tue, 12 June 2012 23:41:58 +00002012-06-12T22:45:47Z"
sAWSAccessKeyId = "AESDQWDQWD"
sSignature=Encrypt("SecretQWEQWEQWEQWEYAYAY")
AWSServiceUrl = "https://s3.amazonaws.com/"
Set oXMLHTTP = Server.CreateObject("MSXML2.ServerXMLHTTP")
oXMLHTTP.open "GET", AWSServiceUrl, False
oXMLHTTP.setRequestHeader "Authorization", "AWS " & sAWSAccessKeyId & ":" & sSignature
oXMLHTTP.setRequestHeader "x-amz-date", sTimeStamp
on error resume next
oXMLHTTP.send sRequest
Response.Write oXMLHTTP.responseText
%>
Any ideas?
The simplest way to do it is to get JScript to help:
<script runat="server" language="javascript">
function JSNow() { return new Date(); }
</script>
Now you can get the string format for the time required with:
Dim sTimeStamp: sTimeStamp = JSNow().toString()

400 Bad Request : Consuming WCF basicHttpBinding (Soap) using JScript/VBScript

var oXMLDoc, oXMLHttp, soapRequest, soapResponse;
oXMLHttp = new ActiveXObject("Microsoft.XMLHTTP");
oXMLHttp.open("POST", "http://nerdbox/HelloService.svc", false);
// Add HTTP headers
oXMLHttp.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
oXMLHttp.setRequestHeader("SOAPAction", "http://tempuri.org/IHelloService/SayHello");
// Form the message
soapRequest = '<?xml version="1.0" encoding="utf-16"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><SayHello xmlns="http://tempuri.org/"><name>Zuhaib</name></SayHello></soap:Body></soap:Envelope>';
WScript.Echo("Request : " + soapRequest);
oXMLHttp.send(soapRequest);
soapResponse = oXMLHttp.responseXML.xml;
WScript.Echo("Respose : " + soapResponse);
Whats wrong with this JScript? why am I getting 400 Bad Request. I read similar threads in stackoverflow .. some say its soap message formatting problem.
This is what the message looks like if I take it from fiddler.
Try changing your action from IHelloService to HelloService.
And let me ask you, why are you doing it the hard way. Just add a webHttpBinding and use JSON.
See a very easy example here.
I had to change your code to the following to get it to run in VBSEdit...then I (obviously) got the error about it not being able to find the resource...but change your code to this and see if it makes a difference?
Dim oXMLDoc, oXMLHttp, soapRequest, soapResponse
Set oXMLHttp = CreateObject("Microsoft.XMLHTTP")
oXMLHttp.open "POST", "http://nerdbox/HelloService.svc", False
'// Add HTTP headers
oXMLHttp.setRequestHeader "Content-Type", "text/xml; charset=utf-8"
oXMLHttp.setRequestHeader "SOAPAction", "http://tempuri.org/IHelloService/SayHello"
'// Form the message
soapRequest = "<?xml version=""1.0"" encoding=""utf-16""?><soap:Envelope xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema""><soap:Body><SayHello xmlns=""http://tempuri.org/""><name>Zuhaib</name></SayHello></soap:Body></soap:Envelope>"
WScript.Echo "Request : " + soapRequest
oXMLHttp.send soapRequest
soapResponse = oXMLHttp.responseXML.xml
WScript.Echo "Respose : " + soapResponse

Sending a 'application/soap+xml' SOAP request using Classic ASP

Any help with this would be appreciated; I've been at it for a few days now.
Below is the code that I've got so far; unfortunatly when I run it I get a HTTP 415 error; Cannot process the message because the content type 'text/xml; charset=UTF-8' was not the expected type 'application/soap+xml; charset=utf-8'.
I have to send the content-type of application/soap+xml as this is the only type that the web service allows; and I have to do it in classic ASP.
I've tried changing the 'send' line to "objRequest.send objXMLDoc.XML" but this then gives me a HTTP 400 Bad Request error.
strXmlToSend = "<some valid xml>"
webserviceurl = "http://webservice.com"
webserviceSOAPActionNameSpace = "avalidnamespace"
Set objRequest = Server.createobject("MSXML2.XMLHTTP.3.0")
objRequest.open "POST", webserviceurl, False
objRequest.setRequestHeader "Content-Type", "application/soap+xml"
objRequest.setRequestHeader "CharSet", "utf-8"
objRequest.setRequestHeader "action", webserviceSOAPActionNameSpace & "GetEstimate"
objRequest.setRequestHeader "SOAPAction", webserviceSOAPActionNameSpace & "GetEstimate"
Set objXMLDoc = Server.createobject("MSXML2.DOMDocument.3.0")
objXMLDoc.loadXml strXmlToSend
objRequest.send objXMLDoc
set objXMLDoc = nothing
Here's what I've used successfully in the past:
Set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP.6.0")
xmlhttp.open "POST", url, false
xmlhttp.setRequestHeader "Content-Type", "text/xml; charset=utf-8"
xmlhttp.setRequestHeader "SOAPAction", "http://www.mydomain.com/myaction"
xmlhttp.send postdata
xml = xmlhttp.responseText
When you pass an XML DOM ot the send method the Content-Type is always set to "text/xml".
If you want to control the content type then you must pass a string. Don't bother loading the XML string into a DOM only to call the xml property since that may change the content of the xml declaration. BTW what does the xml declaration look like in the XML string and are you certain that the xml is correct? The encoding on the xml declare if present should say "UTF-8".
Don't send a header CharSet it means nothing, CharSet is an attribute of the Content-Type header.
Don't use XMLHTTP from inside ASP its not safe.
Hence your code ought to look like this:-
strXmlToSend = "<some valid xml>"
webserviceurl = "http://webservice.com"
webserviceSOAPActionNameSpace = "avalidnamespace"
Set objRequest = Server.Createobject("MSXML2.ServerXMLHTTP.3.0")
objRequest.open "POST", webserviceurl, False
objRequest.setRequestHeader "Content-Type", "application/soap+xml; charset=UTF-8"
objRequest.setRequestHeader "action", webserviceSOAPActionNameSpace & "GetEstimate"
objRequest.setRequestHeader "SOAPAction", webserviceSOAPActionNameSpace & "GetEstimate"
objRequest.send strXmlToSend
Not sure about that "action" header either looks superflous to me. Perhaps this will still fail in some way but it shouldn't complain about the Content-Type header anymore.