Jump to content

Recommended Posts

Posted

Here are some information:

http://ec.europa.eu/taxation_customs/vies/faq.html?locale=en
http://ec.europa.eu/taxation_customs/vies/vatRequest.html?locale=en

and this
http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl

and my questions:

1. Has anyone automate the verification process using this service ?
2. Is this wsdl file is sufficient documentation to establish adequate solution, or you have to have additional documentation / specifications derived from this organization?

 

mLipok

ps.

This be the first time when I will try to use SOAP so I'm fledgling in this matter.

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Posted (edited)

I would be grateful if someone who knows this stuff just said something about (will direct me to the right path), the rest I prefer to read through, some think, and come back with further questions, this way I better assimilate knowledge.

I am glad that there are others interested because the discussion will be more interesting.

 

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Posted (edited)

I use it in my work.

I created function using VIES / SOAP and it works fine for me. In 2010 they changed URLs so I have to modify my function.

Here are general useful SOAP & AutoIt links:

http://stackoverflow.com/questions/124269/simplest-soap-example

***

Here is simplified my function in PowerBuilder syntax (very similar to AutoIt),

comments are in Czech language:

global function string uf_c_kontrola_dic (string dic, ref s_c_kontrola_dic str_dic);
// pri chybe vrati chybove hlaseni
// pri OK vrati prazdny retezec a naplni strukturu

s_sys_http_output output
int i
string ls_pom, ls_xml, ls_xml_data, ls_header, stat, ls_url, ls_action

// na vstupu bude DIC vcetne statu, ale zde se musi rozlozit na stat a samotne cislo dic
stat = Upper(Left(dic,2)) // country
dic = Mid(dic,3) // VAT

ls_url = 'http://ec.europa.eu/taxation_customs/vies/services/checkVatService;checkVat'

ls_pom = uf_parse_string(ls_url, ';')
ls_action = ls_url // nyni uz nevyuzity - not used now
ls_url = ls_pom

ls_xml_data = '<?xml version="1.0" encoding="utf-8"?> ' + &
                  '<soap:Envelope ' + &
                  'xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" ' + &
                  'xmlns:urn="urn:ec.europa.eu:taxud:vies:services:checkVat:types"> ' + &
                  '<soap:Body> ' + &
                  '<urn:checkVat> ' + &
                  '  <urn:countryCode>#stat</urn:countryCode> ' + &
                  '  <urn:vatNumber>#dic</urn:vatNumber> ' + &
                  '</urn:checkVat></soap:Body></soap:Envelope>'

ls_xml_data = uf_replaceall(ls_xml_data, '#stat', stat)
ls_xml_data = uf_replaceall(ls_xml_data, '#dic', dic)

ls_header = 'Content-Type~tText/xml~n' + &
                'SOAPAction~t""'

i = uf_sys_http_prikaz('POST',ls_url,'','',ls_header,ls_xml_data,'','','',output) // wrapper for WinHttp.WinHttpRequest.5.1
IF i <> 0 THEN    RETURN 'Chyba při odesílání HTTP požadavku.~nčíslo chyby: ' + string(i)
//    nf_msgupo(output.status + '~n' + output.statustext + '~n~n' + output.allresponseheaders + '~n~n' + output.responsetext)

// pokud nedojde k chybe obsahuje output.responsetext XML data s vysledkem
// v pripade chyby obsahuje output.responsetext HTML popis chyby
ls_xml = output.responsetext

// POZOR: XML obsahuje ceske znaky zakodovane pomoci HTML, napr: Anton&#xED;n
ls_xml = uf_sys_conv_html_1250(ls_xml)

// HTTP status OK je 200
IF output.status <> '200' THEN
    ls_pom = uf_string_between(ls_xml, '<faultstring>','</faultstring>')
    IF ls_pom <> '' THEN // chyba ze SOAP serveru (v XML tvaru)
        RETURN 'Chyba v XML souboru.~npopis chyby: ' + ls_pom
    ELSE // zrejme chyba HTTP (v HTML tvaru)
        RETURN 'Chyba při odesílání HTTP požadavku.~nstatus text: ' + output.statustext + '~nresponse text: ' + uf_sys_html2txt(output.responsetext)
    END IF
END IF

IF Left(ls_xml,5) = '<?xml' THEN
    str_dic.stat = stat
    str_dic.dic = dic
    str_dic.name = uf_string_between(ls_xml, '<urn:name>','</urn:name>')
    str_dic.address = uf_string_between(ls_xml, '<urn:address>','</urn:address>')
    str_dic.valid = uf_string_between(ls_xml, '<urn:valid>','</urn:valid>')
ELSEIF LEFT(ls_xml,14) = '<soap:Envelope' THEN
    str_dic.stat = stat
    str_dic.dic = dic
    str_dic.name = uf_string_between(ls_xml, '<name>','</name>')
    str_dic.address = uf_string_between(ls_xml, '<address>','</address>')
    str_dic.valid = uf_string_between(ls_xml, '<valid>','</valid>')
ELSE
    RETURN 'Chyba v XML souboru.~nsoubor nemá správnou XML hlavičku~n~n' + ls_xml // v pripade chybne URL muze vratit HTML s chybou
END IF

RETURN ''
end function

 

Edited by Zedna
Posted

What uf_parse_string function doing ?

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Posted

For now I have this (not working yet) script:

#include <String.au3>

Local $oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc")

Local $o_str_dic
uf_c_kontrola_dic('PL123456789123', $o_str_dic);

Func uf_c_kontrola_dic($sDic, ByRef $o_str_dic);
    ; pri chybe vrati chybove hlaseni
    ; pri OK vrati prazdny retezec a naplni strukturu

    Local $oOutput
    Local $i
    Local $s_ls_pom, $s_ls_xml, $s_ls_xml_data, $s_ls_header, $sStat, $s_ls_url, $s_ls_action

    ; na vstupu bude DIC vcetne statu, ale zde se musi rozlozit na stat a samotne cislo dic
    $sStat = StringUpper(StringLeft($sDic, 2)) ; country
    $sDic = StringMid($sDic, 3) ; VAT

    $s_ls_url = 'http:;ec.europa.eu/taxation_customs/vies/services/checkVatService;checkVat'

    $s_ls_pom = uf_parse_string($s_ls_url, ';')
    $s_ls_action = $s_ls_url ; nyni uz nevyuzity - not used now
    $s_ls_url = $s_ls_pom

    $s_ls_xml_data = '<?xml version="1.0" encoding="utf-8"?> ' & _
            '<soap:Envelope ' & _
            'xmlns:soap="http:;schemas.xmlsoap.org/soap/envelope/" ' & _
            'xmlns:urn="urn:ec.europa.eu:taxud:vies:services:checkVat:types"> ' & _
            '<soap:Body> ' & _
            '<urn:checkVat> ' & _
            '  <urn:countryCode>#$sStat</urn:countryCode> ' & _
            '  <urn:vatNumber>#$sDic</urn:vatNumber> ' & _
            '</urn:checkVat></soap:Body></soap:Envelope>'

    $s_ls_xml_data = StringReplace($s_ls_xml_data, '#$sStat', $sStat)
    $s_ls_xml_data = StringReplace($s_ls_xml_data, '#$sDic', $sDic)

    $s_ls_header = _
            'Content-Type' & @TAB & 'Text/xml' & @CRLF & _
            'SOAPAction' & @TAB & '""'

;~  $i = uf_sys_http_prikaz('POST', $s_ls_url, '', '', $s_ls_header, $s_ls_xml_data, '', '', '', $oOutput) ; wrapper for WinHttp.WinHttpRequest.5.1
    $i = _SOAP_Api_Sender('POST', $s_ls_url, $s_ls_header, $s_ls_xml_data, $oOutput) ; wrapper for WinHttp.WinHttpRequest.5.1

    If $i <> 0 Then
        Return 'Chyba při odesílání HTTP požadavku.' & @CRLF & 'číslo chyby: ' & String($i)
    EndIf
    ;    nf_msgupo($oOutput.status + '~n' + $oOutput.statustext + '~n~n' + $oOutput.allresponseheaders + '~n~n' + $oOutput.responsetext)

    ; pokud nedojde k chybe obsahuje $oOutput.responsetext XML data s vysledkem
    ; v pripade chyby obsahuje $oOutput.responsetext HTML popis chyby
    $s_ls_xml = $oOutput.responsetext

    ; POZOR: XML obsahuje ceske znaky zakodovane pomoci HTML, napr: Anton&#xED;n
;~ $s_ls_xml = uf_sys_conv_html_1250($s_ls_xml)

    ; HTTP status OK je 200
    If $oOutput.status <> '200' Then
        $s_ls_pom = _StringBetween($s_ls_xml, '<faultstring>', '</faultstring>')
        If $s_ls_pom <> '' Then ; chyba ze SOAP serveru (v XML tvaru)
            Return 'Chyba v XML souboru.~npopis chyby: ' & $s_ls_pom
        Else ; zrejme chyba HTTP (v HTML tvaru)
;~          Return 'Chyba při odesílání HTTP požadavku.~nstatus text: ' + $oOutput.statustext + '~nresponse text: ' + uf_sys_html2txt($oOutput.responsetext)
            Return 'Chyba při odesílání HTTP požadavku.' & @CRLF & 'status text: ' & $oOutput.statustext & @CRLF & 'response text: ' & $oOutput.responsetext
        EndIf
    EndIf

    If StringLeft($s_ls_xml, 5) = '<?xml' Then
        MsgBox(0, '$s_ls_xml', $s_ls_xml)

        #cs
            $o_str_dic.stat = $sStat
            $o_str_dic.dic = $sDic
            $o_str_dic.name = _StringBetween($s_ls_xml, '<urn:name>', '</urn:name>')
            $o_str_dic.address = _StringBetween($s_ls_xml, '<urn:address>', '</urn:address>')
            $o_str_dic.valid = _StringBetween($s_ls_xml, '<urn:valid>', '</urn:valid>')

        #CE
    ElseIf StringLeft($s_ls_xml, 14) = '<soap:Envelope' Then
        MsgBox(0, '$s_ls_xml', $s_ls_xml)

        #CS
            $o_str_dic.stat = $sStat
            $o_str_dic.dic = $sDic
            $o_str_dic.name = _StringBetween($s_ls_xml, '<name>', '</name>')
            $o_str_dic.address = _StringBetween($s_ls_xml, '<address>', '</address>')
            $o_str_dic.valid = _StringBetween($s_ls_xml, '<valid>', '</valid>')

        #CE
    Else
        Return 'Chyba v XML souboru.' & @CRLF & 'nsoubor nemá správnou XML hlavičku' & @CRLF & @CRLF & $s_ls_xml ; v pripade chybne URL muze vratit HTML s chybou
    EndIf

    Return ''
EndFunc   ;==>uf_c_kontrola_dic


Func _SOAP_Api_Sender($sType, $s_ls_url, $s_ls_header, $s_ls_xml_data, ByRef $oOutput)
    $objHTTP = ObjCreate("Microsoft.XMLHTTP")
    $objReturn = ObjCreate("Msxml2.DOMdocument.3.0")

    ; Create the SOAP Envelope
    $strEnvelope = $s_ls_xml_data

    ; Set up to post to our local server
    $objHTTP.open("post", $s_ls_url, False)

    ; Set a standard SOAP/ XML header for the content-type
    $objHTTP.setRequestHeader("Content-Type", "text/xml")
;~  $objHTTP.setRequestHeader("Content-Type", $s_ls_header)

    ; Set a header for the method to be called
;~  $objHTTP.setRequestHeader("SOAPMethodName", "urn:myserver/soap:TaxCalculator#getsalestax")
    $objHTTP.setRequestHeader("SOAPAction", "")

    ConsoleWrite("Content of the Soap envelope : " & @CR & $strEnvelope & @CR & @CR)

    ; Make the SOAP call
    $objHTTP.send($strEnvelope)
    $oOutput = $objHTTP

EndFunc   ;==>_SOAP_Api_Sender


; User's COM error function. Will be called if COM error occurs
Func _ErrFunc($oError)
    ; Do anything here.
    ConsoleWrite(@ScriptName & " (" & $oError.scriptline & ") : ==> COM Error intercepted !" & @CRLF & _
            @TAB & "err.number is: " & @TAB & @TAB & "0x" & Hex($oError.number) & @CRLF & _
            @TAB & "err.windescription:" & @TAB & $oError.windescription & @CRLF & _
            @TAB & "err.description is: " & @TAB & $oError.description & @CRLF & _
            @TAB & "err.source is: " & @TAB & @TAB & $oError.source & @CRLF & _
            @TAB & "err.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _
            @TAB & "err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _
            @TAB & "err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _
            @TAB & "err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _
            @TAB & "err.retcode is: " & @TAB & "0x" & Hex($oError.retcode) & @CRLF & @CRLF)
EndFunc   ;==>_ErrFunc

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Posted (edited)

Here is simplified wrapper for WinHttp.WinHttpRequest.5.1 (function uf_sys_http_prikaz) used in my previous example

global function integer uf_sys_http_prikaz (readonly string prikaz, readonly string url, readonly string jmeno, readonly string heslo, string hlavicka, readonly string data, ref s_sys_http_output output);

// prikaz - GET/PUT/POST/...
// url - https://www.server.com:port/adresar
// hlavicka - seznam vsech udaju hlavicky ve tvaru: nazev1~thodnota1~nnazev2~thodnota2~nnazev3~thodnota3

// pri chybe vrati zaporny chybovy kod
// pri OK vrati 0

INTEGER HTTPREQUEST_PROXYSETTING_DEFAULT = 0
INTEGER HTTPREQUEST_PROXYSETTING_PRECONFIG = 0
INTEGER HTTPREQUEST_PROXYSETTING_DIRECT = 1
INTEGER HTTPREQUEST_PROXYSETTING_PROXY = 2 
INTEGER HTTPREQUEST_SETCREDENTIALS_FOR_SERVER = 0
INTEGER HTTPREQUEST_SETCREDENTIALS_FOR_PROXY = 1

string ls_hlavicka_cast, ls_nazev, ls_hodnota
integer result

OLEObject oHttpRequest
oHttpRequest = CREATE OLEObject
result = oHttpRequest.ConnectToNewObject("WinHttp.WinHttpRequest.5.1")

oHttpRequest.Open(prikaz, url, False)
if jmeno <> '' then oHttpRequest.SetCredentials(jmeno, heslo, HTTPREQUEST_SETCREDENTIALS_FOR_SERVER) // name,password

if hlavicka <> '' then // header
    // pozn: udaje hlavicky se musi nastavit po jednom
    DO WHILE hlavicka <> ''
        ls_hlavicka_cast = uf_parse_string(hlavicka,'~n') // nazev1~thodnota1
        ls_nazev = uf_parse_string(ls_hlavicka_cast,'~t')
        ls_hodnota = ls_hlavicka_cast
        oHttpRequest.SetRequestHeader(ls_nazev, ls_hodnota)
    LOOP
end if

oHttpRequest.Send(data)

output.Status = string(oHttpRequest.Status) 
output.StatusText = oHttpRequest.StatusText
output.AllResponseHeaders = oHttpRequest.GetAllResponseHeaders()
output.ResponseText = oHttpRequest.ResponseText

oHttpRequest.DisconnectObject()
DESTROY oHttpRequest
return 0
end function

 

Edited by Zedna
  • 3 months later...
Posted (edited)

I'm back to this.

And have some problems:

#include <String.au3>
#include <array.au3>

Global Enum _
        $__g_iOutput_Status, _
        $__g_iOutput_StatusText, _
        $__g_iOutput_AllResponseHeaders, _
        $__g_iOutput_ResponseText, _
        $__g_iOutput_ENUMCOUNTER

Local $oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc")

Local $o_str_dic
; check TeamViewer GmbH NIP
MsgBox(0, '', uf_c_kontrola_dic('DE245838579', $o_str_dic))

Func uf_c_kontrola_dic($sDic, ByRef $o_str_dic)
    ; pri chybe vrati chybove hlaseni
    ; pri OK vrati prazdny retezec a naplni strukturu

    Local $aOutput[$__g_iOutput_ENUMCOUNTER]
    Local $i
    Local $spom, $sXML, $sXML_data, $sHeader, $sStat, $sURL, $saction

    ; na vstupu bude DIC vcetne statu, ale zde se musi rozlozit na stat a samotne cislo dic
    $sStat = StringUpper(StringLeft($sDic, 2)) ; country
    $sDic = StringMid($sDic, 3) ; VAT

    $sURL = 'http://ec.europa.eu/taxation_customs/vies/services/checkVatService;checkVat'

    $spom = StringSplit($sURL, ';')[1]
    $saction = $sURL ; nyni uz nevyuzity - not used now
    $sURL = $spom

    $sXML_data = '<?xml version="1.0" encoding="utf-8"?> ' & _
            '<soap:Envelope ' & _
            'xmlns:soap="http:;schemas.xmlsoap.org/soap/envelope/" ' & _
            'xmlns:urn="urn:ec.europa.eu:taxud:vies:services:checkVat:types"> ' & _
            '<soap:Body> ' & _
            '<urn:checkVat> ' & _
            '  <urn:countryCode>#$sStat</urn:countryCode> ' & _
            '  <urn:vatNumber>#$sDic</urn:vatNumber> ' & _
            '</urn:checkVat></soap:Body></soap:Envelope>'

    $sXML_data = StringReplace($sXML_data, '#$sStat', $sStat)
    $sXML_data = StringReplace($sXML_data, '#$sDic', $sDic)

    $sHeader = _
            'Content-Type' & @TAB & 'Text/xml' & @CRLF & _
            'SOAPAction' & @TAB & '""'

    $i = uf_sys_http_prikaz('POST', $sURL, '', '', $sHeader, $sXML_data, $aOutput) ; wrapper for WinHttp.WinHttpRequest.5.1
    If $i <> 0 Then
        Return 'Chyba při odesílání HTTP požadavku.' & @CRLF & 'číslo chyby: ' & String($i)
    EndIf

    If Not @Compiled Then _ArrayDisplay($aOutput)
    ; nf_msgupo($aOutput[$__g_iOutput_Status] + '~n' + $aOutput[$__g_iOutput_StatusText] + '~n~n' + $aOutput[$__g_iOutput_allresponseheaders]  + '~n~n' + $aOutput[$__g_iOutput_responsetext])

    ; pokud nedojde k chybe obsahuje $aOutput[$__g_iOutput_responsetext] XML data s vysledkem
    ; v pripade chyby obsahuje $aOutput[$__g_iOutput_responsetext] HTML popis chyby
    $sXML = $aOutput[$__g_iOutput_ResponseText]

    ; POZOR: XML obsahuje ceske znaky zakodovane pomoci HTML, napr: Anton&#xED;n
    ; $sXML = uf_sys_conv_html_1250($sXML)

    ; HTTP status OK je 200
    If $aOutput[$__g_iOutput_status] <> '200' Then
        $spom = _StringBetween($sXML, '<faultstring>', '</faultstring>')
        If $spom <> '' Then ; chyba ze SOAP serveru (v XML tvaru)
            Return 'Chyba v XML souboru.~npopis chyby: ' & $spom
        Else ; zrejme chyba HTTP (v HTML tvaru)
;~          Return 'Chyba při odesílání HTTP požadavku.~nstatus text: ' + $aOutput[$__g_iOutput_statustext] + '~nresponse text: ' + uf_sys_html2txt($aOutput[$__g_iOutput_responsetext])
            Return 'Chyba při odesílání HTTP požadavku.' & @CRLF & 'status text: ' & $aOutput[$__g_iOutput_statustext] & @CRLF & 'response text: ' & $aOutput[$__g_iOutput_responsetext]
        EndIf
    EndIf

    If StringLeft($sXML, 5) = '<?xml' Then
        MsgBox(0, '$sXML', $sXML)

        #cs
            $o_str_dic.stat = $sStat
            $o_str_dic.dic = $sDic
            $o_str_dic.name = _StringBetween($sXML, '<urn:name>', '</urn:name>')
            $o_str_dic.address = _StringBetween($sXML, '<urn:address>', '</urn:address>')
            $o_str_dic.valid = _StringBetween($sXML, '<urn:valid>', '</urn:valid>')

        #ce
    ElseIf StringLeft($sXML, 14) = '<soap:Envelope' Then
        MsgBox(0, '$sXML', $sXML)

        #cs
            $o_str_dic.stat = $sStat
            $o_str_dic.dic = $sDic
            $o_str_dic.name = _StringBetween($sXML, '<name>', '</name>')
            $o_str_dic.address = _StringBetween($sXML, '<address>', '</address>')
            $o_str_dic.valid = _StringBetween($sXML, '<valid>', '</valid>')

        #ce
    Else
        Return 'Chyba v XML souboru.' & @CRLF & 'nsoubor nemá správnou XML hlavičku' & @CRLF & @CRLF & $sXML ; v pripade chybne URL muze vratit HTML s chybou
    EndIf

    Return ''
EndFunc   ;==>uf_c_kontrola_dic

Func uf_sys_http_prikaz(Const $sCOMMAND, Const $sURL, Const $sUserName, Const $sPassword, $sHeader, Const $sXML_data, ByRef $aOutput)

    ; $sCOMMAND - GET/PUT/POST/...
    ; $sURL - https:;www.server.com:port/adresar
    ; $sHeader - seznam vsech udaju hlavicky ve tvaru: Title1~tValue1~nTitle2~tValue2~nTitle3~tValue3

    ; pri chybe vrati zaporny chybovy kod
    ; pri OK vrati 0

    Local $iHTTPREQUEST_PROXYSETTING_DEFAULT = 0
    Local $iHTTPREQUEST_PROXYSETTING_PRECONFIG = 0
    Local $iHTTPREQUEST_PROXYSETTING_DIRECT = 1
    Local $iHTTPREQUEST_PROXYSETTING_PROXY = 2
    Local $iHTTPREQUEST_SETCREDENTIALS_FOR_SERVER = 0
    Local $iHTTPREQUEST_SETCREDENTIALS_FOR_PROXY = 1

    Local $sHeader_cast, $sTitle, $sValue
    Local $oHttpRequest = ObjCreate('WinHttp.WinHttpRequest.5.1')

    $oHttpRequest.Open($sCOMMAND, $sURL, False)
    If $sUserName <> '' Then $oHttpRequest.SetCredentials($sUserName, $sPassword, $iHTTPREQUEST_SETCREDENTIALS_FOR_SERVER) ; name, password

    If $sHeader <> '' Then ; header
        ; pozn: udaje hlavicky se musi nastavit po jednom

        ; While $sHeader <> ''
        $sHeader_cast = StringSplit($sHeader, '~n')[1] ; Title1~tValue1
        $sTitle = StringSplit($sHeader_cast, '~t')[1]
        $sValue = $sHeader_cast
        $oHttpRequest.SetRequestHeader($sTitle, $sValue)
        ;WEnd
    EndIf

    $oHttpRequest.Send($sXML_data)

    $aOutput[$__g_iOutput_Status] = String($oHttpRequest.Status)
    $aOutput[$__g_iOutput_Status] = $oHttpRequest.StatusText
    $aOutput[$__g_iOutput_AllResponseHeaders] = $oHttpRequest.GetAllResponseHeaders()
    $aOutput[$__g_iOutput_ResponseText] = $oHttpRequest.ResponseText

    $oHttpRequest = Null
    Return 0
EndFunc   ;==>uf_sys_http_prikaz

Func _ConsoleOut($string)
    ConsoleWrite(BinaryToString(StringToBinary($string, 4), 1) & @CRLF)
EndFunc   ;==>_ConsoleOut

; User's COM error function. Will be called if COM error occurs
Func _ErrFunc($oError)
    ; Do anything here.
    _ConsoleOut(@ScriptName & " (" & $oError.scriptline & ") : ==> COM Error intercepted !" & @CRLF & _
            @TAB & "err.number is: " & @TAB & @TAB & "0x" & Hex($oError.number) & @CRLF & _
            @TAB & "err.windescription:" & @TAB & $oError.windescription & @CRLF & _
            @TAB & "err.description is: " & @TAB & $oError.description & @CRLF & _
            @TAB & "err.source is: " & @TAB & @TAB & $oError.source & @CRLF & _
            @TAB & "err.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _
            @TAB & "err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _
            @TAB & "err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _
            @TAB & "err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _
            @TAB & "err.retcode is: " & @TAB & "0x" & Hex($oError.retcode) & @CRLF & @CRLF)
EndFunc   ;==>_ErrFunc

 

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Posted (edited)

It works :cheer:

;~ http://ec.europa.eu/taxation_customs/vies/technicalInformation.html

#include <String.au3>
#include <array.au3>

Global Enum _
        $__g_iOutput_Status, _
        $__g_iOutput_StatusText, _
        $__g_iOutput_AllResponseHeaders, _
        $__g_iOutput_ResponseText, _
        $__g_iOutput_ENUMCOUNTER

Local $o_str_dic
; Checking: TeamViewer GmbH NIP
MsgBox(0, '', uf_c_kontrola_dic('DE245838579', $o_str_dic))
; Checking: Avangate BV
MsgBox(0, '', uf_c_kontrola_dic('NL815605468B01', $o_str_dic))

Func uf_c_kontrola_dic($sDic, ByRef $o_str_dic)
    ; pri chybe vrati chybove hlaseni
    ; pri OK vrati prazdny retezec a naplni strukturu

    Local $aOutput[$__g_iOutput_ENUMCOUNTER]
    Local $i
    Local $spom, $sXML, $sXML_data, $sHeader, $sStat, $sURL, $saction

    ; na vstupu bude DIC vcetne statu, ale zde se musi rozlozit na stat a samotne cislo dic
    $sStat = StringUpper(StringLeft($sDic, 2)) ; country
    $sDic = StringMid($sDic, 3) ; VAT

    $sURL = 'http://ec.europa.eu/taxation_customs/vies/services/checkVatService;checkVat'

    $spom = StringSplit($sURL, ';')[1]
    $saction = $sURL ; nyni uz nevyuzity - not used now
    $sURL = $spom

;~  $sXML_data = '<?xml version="1.0" encoding="utf-8"?> ' & _


    #cs http://ec.europa.eu/taxation_customs/vies/technicalInformation.html
        ; <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:ec.europa.eu:taxud:vies:services:checkVat:types">
        ;    <soapenv:Header/>
        ;    <soapenv:Body>
        ;       <urn:checkVat>
        ;          <urn:countryCode>MS</urn:countryCode>
        ;          <urn:vatNumber>TESTVATNUMBER</urn:vatNumber>
        ;       </urn:checkVat>
        ;    </soapenv:Body>
        ; </soapenv:Envelope>
    #ce
    
    $sXML_data = _
            '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:ec.europa.eu:taxud:vies:services:checkVat:types"> ' & _
            '   <soapenv:Header/>' & _
            '   <soapenv:Body>' & _
            '      <urn:checkVat>' & _
            '         <urn:countryCode>' & $sStat & '</urn:countryCode>' & _
            '         <urn:vatNumber>' & $sDic & '</urn:vatNumber>' & _
            '      </urn:checkVat>' & _
            '   </soapenv:Body>' & _
            '</soapenv:Envelope>' & _
            ''

    $sHeader = _
            'Content-Type' & @TAB & 'Text/xml' & @CRLF & _
            'SOAPAction' & @TAB & '""'

    $i = uf_sys_http_prikaz('POST', $sURL, '', '', $sHeader, $sXML_data, $aOutput) ; wrapper for WinHttp.WinHttpRequest.5.1
    If $i <> 0 Then
        Return 'Chyba při odesílání HTTP požadavku.' & @CRLF & 'číslo chyby: ' & String($i)
    EndIf

    If Not @Compiled Then _ArrayDisplay($aOutput)
    ; nf_msgupo($aOutput[$__g_iOutput_Status] + '~n' + $aOutput[$__g_iOutput_StatusText] + '~n~n' + $aOutput[$__g_iOutput_allresponseheaders]  + '~n~n' + $aOutput[$__g_iOutput_responsetext])

    ; pokud nedojde k chybe obsahuje $aOutput[$__g_iOutput_responsetext] XML data s vysledkem
    ; v pripade chyby obsahuje $aOutput[$__g_iOutput_responsetext] HTML popis chyby
    $sXML = $aOutput[$__g_iOutput_ResponseText]

    ; POZOR: XML obsahuje ceske znaky zakodovane pomoci HTML, napr: Antonín
    ; $sXML = uf_sys_conv_html_1250($sXML)

    ; HTTP status OK je 200
    If $aOutput[$__g_iOutput_status] <> '200' Then
        $spom = _StringBetween($sXML, '<faultstring>', '</faultstring>')
        If $spom <> '' Then ; chyba ze SOAP serveru (v XML tvaru)
            Return 'Chyba v XML souboru.~npopis chyby: ' & $spom
        Else ; zrejme chyba HTTP (v HTML tvaru)
;~          Return 'Chyba při odesílání HTTP požadavku.~nstatus text: ' + $aOutput[$__g_iOutput_statustext] + '~nresponse text: ' + uf_sys_html2txt($aOutput[$__g_iOutput_responsetext])
            Return 'Chyba při odesílání HTTP požadavku.' & @CRLF & 'status text: ' & $aOutput[$__g_iOutput_statustext] & @CRLF & 'response text: ' & $aOutput[$__g_iOutput_responsetext]
        EndIf
    EndIf

    If StringLeft($sXML, 5) = '<?xml' Then
        MsgBox(0, '$sXML', $sXML)

        #cs
            $o_str_dic.stat = $sStat
            $o_str_dic.dic = $sDic
            $o_str_dic.name = _StringBetween($sXML, '<urn:name>', '</urn:name>')
            $o_str_dic.address = _StringBetween($sXML, '<urn:address>', '</urn:address>')
            $o_str_dic.valid = _StringBetween($sXML, '<urn:valid>', '</urn:valid>')

        #ce
    ElseIf StringLeft($sXML, 14) = '<soap:Envelope' Then
        MsgBox(0, '$sXML', $sXML)

        #cs
            $o_str_dic.stat = $sStat
            $o_str_dic.dic = $sDic
            $o_str_dic.name = _StringBetween($sXML, '<name>', '</name>')
            $o_str_dic.address = _StringBetween($sXML, '<address>', '</address>')
            $o_str_dic.valid = _StringBetween($sXML, '<valid>', '</valid>')

        #ce
    Else
        Return 'Chyba v XML souboru.' & @CRLF & 'nsoubor nemá správnou XML hlavičku' & @CRLF & @CRLF & $sXML ; v pripade chybne URL muze vratit HTML s chybou
    EndIf

    Return ''
EndFunc   ;==>uf_c_kontrola_dic

Func uf_sys_http_prikaz(Const $sCOMMAND, Const $sURL, Const $sUserName, Const $sPassword, $sHeader, Const $sXML_data, ByRef $aOutput)

    If Not @Compiled Then ConsoleWrite($sXML_data & @CRLF)
    ; $sCOMMAND - GET/PUT/POST/...
    ; $sURL - https:;www.server.com:port/adresar
    ; $sHeader - seznam vsech udaju hlavicky ve tvaru: Title1~tValue1~nTitle2~tValue2~nTitle3~tValue3

    ; pri chybe vrati zaporny chybovy kod
    ; pri OK vrati 0

    Local $iHTTPREQUEST_PROXYSETTING_DEFAULT = 0
    Local $iHTTPREQUEST_PROXYSETTING_PRECONFIG = 0
    Local $iHTTPREQUEST_PROXYSETTING_DIRECT = 1
    Local $iHTTPREQUEST_PROXYSETTING_PROXY = 2
    Local $iHTTPREQUEST_SETCREDENTIALS_FOR_SERVER = 0
    Local $iHTTPREQUEST_SETCREDENTIALS_FOR_PROXY = 1

    Local $sHeader_cast, $sTitle, $sValue

    Local $oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc")
    Local $oHttpRequest = ObjCreate('WinHttp.WinHttpRequest.5.1')

    $oHttpRequest.Open($sCOMMAND, $sURL, False)
    If $sUserName <> '' Then $oHttpRequest.SetCredentials($sUserName, $sPassword, $iHTTPREQUEST_SETCREDENTIALS_FOR_SERVER) ; name, password

    If $sHeader <> '' Then ; header
        ; pozn: udaje hlavicky se musi nastavit po jednom

        ; While $sHeader <> ''
        $sHeader_cast = StringSplit($sHeader, '~n')[1] ; Title1~tValue1
        $sTitle = StringSplit($sHeader_cast, '~t')[1]
        $sValue = $sHeader_cast
        $oHttpRequest.SetRequestHeader($sTitle, $sValue)
        ;WEnd
    EndIf

    $oHttpRequest.Send($sXML_data)

    $aOutput[$__g_iOutput_Status] = String($oHttpRequest.Status)
    $aOutput[$__g_iOutput_Status] = $oHttpRequest.StatusText
    $aOutput[$__g_iOutput_AllResponseHeaders] = $oHttpRequest.GetAllResponseHeaders()
    $aOutput[$__g_iOutput_ResponseText] = $oHttpRequest.ResponseText

    $oHttpRequest = Null
    Return 0
EndFunc   ;==>uf_sys_http_prikaz

Func _ConsoleOut($string)
    ConsoleWrite(BinaryToString(StringToBinary($string, 4), 1) & @CRLF)
EndFunc   ;==>_ConsoleOut

; User's COM error function. Will be called if COM error occurs
Func _ErrFunc($oError)
    ; Do anything here.
    _ConsoleOut(@ScriptName & " (" & $oError.scriptline & ") : ==> COM Error intercepted !" & @CRLF & _
            @TAB & "err.number is: " & @TAB & @TAB & "0x" & Hex($oError.number) & @CRLF & _
            @TAB & "err.windescription:" & @TAB & $oError.windescription & @CRLF & _
            @TAB & "err.description is: " & @TAB & $oError.description & @CRLF & _
            @TAB & "err.source is: " & @TAB & @TAB & $oError.source & @CRLF & _
            @TAB & "err.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _
            @TAB & "err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _
            @TAB & "err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _
            @TAB & "err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _
            @TAB & "err.retcode is: " & @TAB & "0x" & Hex($oError.retcode) & @CRLF & @CRLF)
EndFunc   ;==>_ErrFunc

 

Edited by mLipok
#CS >> #cs

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

  • 5 years later...
Posted
6 minutes ago, maniootek said:

I tested your code

Which one ? Mine recent version ?

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Posted
On 10/7/2015 at 12:51 AM, mLipok said:

It works :cheer:

;~ http://ec.europa.eu/taxation_customs/vies/technicalInformation.html

#include <String.au3>
#include <array.au3>

Global Enum _
        $__g_iOutput_Status, _
        $__g_iOutput_StatusText, _
        $__g_iOutput_AllResponseHeaders, _
        $__g_iOutput_ResponseText, _
        $__g_iOutput_ENUMCOUNTER

Local $o_str_dic
; Checking: TeamViewer GmbH NIP
MsgBox(0, '', uf_c_kontrola_dic('DE245838579', $o_str_dic))
; Checking: Avangate BV
MsgBox(0, '', uf_c_kontrola_dic('NL815605468B01', $o_str_dic))

Func uf_c_kontrola_dic($sDic, ByRef $o_str_dic)
    ; pri chybe vrati chybove hlaseni
    ; pri OK vrati prazdny retezec a naplni strukturu

    Local $aOutput[$__g_iOutput_ENUMCOUNTER]
    Local $i
    Local $spom, $sXML, $sXML_data, $sHeader, $sStat, $sURL, $saction

    ; na vstupu bude DIC vcetne statu, ale zde se musi rozlozit na stat a samotne cislo dic
    $sStat = StringUpper(StringLeft($sDic, 2)) ; country
    $sDic = StringMid($sDic, 3) ; VAT

    $sURL = 'http://ec.europa.eu/taxation_customs/vies/services/checkVatService;checkVat'

    $spom = StringSplit($sURL, ';')[1]
    $saction = $sURL ; nyni uz nevyuzity - not used now
    $sURL = $spom

;~  $sXML_data = '<?xml version="1.0" encoding="utf-8"?> ' & _


    #cs http://ec.europa.eu/taxation_customs/vies/technicalInformation.html
        ; <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:ec.europa.eu:taxud:vies:services:checkVat:types">
        ;    <soapenv:Header/>
        ;    <soapenv:Body>
        ;       <urn:checkVat>
        ;          <urn:countryCode>MS</urn:countryCode>
        ;          <urn:vatNumber>TESTVATNUMBER</urn:vatNumber>
        ;       </urn:checkVat>
        ;    </soapenv:Body>
        ; </soapenv:Envelope>
    #ce
    
    $sXML_data = _
            '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:ec.europa.eu:taxud:vies:services:checkVat:types"> ' & _
            '   <soapenv:Header/>' & _
            '   <soapenv:Body>' & _
            '      <urn:checkVat>' & _
            '         <urn:countryCode>' & $sStat & '</urn:countryCode>' & _
            '         <urn:vatNumber>' & $sDic & '</urn:vatNumber>' & _
            '      </urn:checkVat>' & _
            '   </soapenv:Body>' & _
            '</soapenv:Envelope>' & _
            ''

    $sHeader = _
            'Content-Type' & @TAB & 'Text/xml' & @CRLF & _
            'SOAPAction' & @TAB & '""'

    $i = uf_sys_http_prikaz('POST', $sURL, '', '', $sHeader, $sXML_data, $aOutput) ; wrapper for WinHttp.WinHttpRequest.5.1
    If $i <> 0 Then
        Return 'Chyba při odesílání HTTP požadavku.' & @CRLF & 'číslo chyby: ' & String($i)
    EndIf

    If Not @Compiled Then _ArrayDisplay($aOutput)
    ; nf_msgupo($aOutput[$__g_iOutput_Status] + '~n' + $aOutput[$__g_iOutput_StatusText] + '~n~n' + $aOutput[$__g_iOutput_allresponseheaders]  + '~n~n' + $aOutput[$__g_iOutput_responsetext])

    ; pokud nedojde k chybe obsahuje $aOutput[$__g_iOutput_responsetext] XML data s vysledkem
    ; v pripade chyby obsahuje $aOutput[$__g_iOutput_responsetext] HTML popis chyby
    $sXML = $aOutput[$__g_iOutput_ResponseText]

    ; POZOR: XML obsahuje ceske znaky zakodovane pomoci HTML, napr: Antonín
    ; $sXML = uf_sys_conv_html_1250($sXML)

    ; HTTP status OK je 200
    If $aOutput[$__g_iOutput_status] <> '200' Then
        $spom = _StringBetween($sXML, '<faultstring>', '</faultstring>')
        If $spom <> '' Then ; chyba ze SOAP serveru (v XML tvaru)
            Return 'Chyba v XML souboru.~npopis chyby: ' & $spom
        Else ; zrejme chyba HTTP (v HTML tvaru)
;~          Return 'Chyba při odesílání HTTP požadavku.~nstatus text: ' + $aOutput[$__g_iOutput_statustext] + '~nresponse text: ' + uf_sys_html2txt($aOutput[$__g_iOutput_responsetext])
            Return 'Chyba při odesílání HTTP požadavku.' & @CRLF & 'status text: ' & $aOutput[$__g_iOutput_statustext] & @CRLF & 'response text: ' & $aOutput[$__g_iOutput_responsetext]
        EndIf
    EndIf

    If StringLeft($sXML, 5) = '<?xml' Then
        MsgBox(0, '$sXML', $sXML)

        #cs
            $o_str_dic.stat = $sStat
            $o_str_dic.dic = $sDic
            $o_str_dic.name = _StringBetween($sXML, '<urn:name>', '</urn:name>')
            $o_str_dic.address = _StringBetween($sXML, '<urn:address>', '</urn:address>')
            $o_str_dic.valid = _StringBetween($sXML, '<urn:valid>', '</urn:valid>')

        #ce
    ElseIf StringLeft($sXML, 14) = '<soap:Envelope' Then
        MsgBox(0, '$sXML', $sXML)

        #cs
            $o_str_dic.stat = $sStat
            $o_str_dic.dic = $sDic
            $o_str_dic.name = _StringBetween($sXML, '<name>', '</name>')
            $o_str_dic.address = _StringBetween($sXML, '<address>', '</address>')
            $o_str_dic.valid = _StringBetween($sXML, '<valid>', '</valid>')

        #ce
    Else
        Return 'Chyba v XML souboru.' & @CRLF & 'nsoubor nemá správnou XML hlavičku' & @CRLF & @CRLF & $sXML ; v pripade chybne URL muze vratit HTML s chybou
    EndIf

    Return ''
EndFunc   ;==>uf_c_kontrola_dic

Func uf_sys_http_prikaz(Const $sCOMMAND, Const $sURL, Const $sUserName, Const $sPassword, $sHeader, Const $sXML_data, ByRef $aOutput)

    If Not @Compiled Then ConsoleWrite($sXML_data & @CRLF)
    ; $sCOMMAND - GET/PUT/POST/...
    ; $sURL - https:;www.server.com:port/adresar
    ; $sHeader - seznam vsech udaju hlavicky ve tvaru: Title1~tValue1~nTitle2~tValue2~nTitle3~tValue3

    ; pri chybe vrati zaporny chybovy kod
    ; pri OK vrati 0

    Local $iHTTPREQUEST_PROXYSETTING_DEFAULT = 0
    Local $iHTTPREQUEST_PROXYSETTING_PRECONFIG = 0
    Local $iHTTPREQUEST_PROXYSETTING_DIRECT = 1
    Local $iHTTPREQUEST_PROXYSETTING_PROXY = 2
    Local $iHTTPREQUEST_SETCREDENTIALS_FOR_SERVER = 0
    Local $iHTTPREQUEST_SETCREDENTIALS_FOR_PROXY = 1

    Local $sHeader_cast, $sTitle, $sValue

    Local $oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc")
    Local $oHttpRequest = ObjCreate('WinHttp.WinHttpRequest.5.1')

    $oHttpRequest.Open($sCOMMAND, $sURL, False)
    If $sUserName <> '' Then $oHttpRequest.SetCredentials($sUserName, $sPassword, $iHTTPREQUEST_SETCREDENTIALS_FOR_SERVER) ; name, password

    If $sHeader <> '' Then ; header
        ; pozn: udaje hlavicky se musi nastavit po jednom

        ; While $sHeader <> ''
        $sHeader_cast = StringSplit($sHeader, '~n')[1] ; Title1~tValue1
        $sTitle = StringSplit($sHeader_cast, '~t')[1]
        $sValue = $sHeader_cast
        $oHttpRequest.SetRequestHeader($sTitle, $sValue)
        ;WEnd
    EndIf

    $oHttpRequest.Send($sXML_data)

    $aOutput[$__g_iOutput_Status] = String($oHttpRequest.Status)
    $aOutput[$__g_iOutput_Status] = $oHttpRequest.StatusText
    $aOutput[$__g_iOutput_AllResponseHeaders] = $oHttpRequest.GetAllResponseHeaders()
    $aOutput[$__g_iOutput_ResponseText] = $oHttpRequest.ResponseText

    $oHttpRequest = Null
    Return 0
EndFunc   ;==>uf_sys_http_prikaz

Func _ConsoleOut($string)
    ConsoleWrite(BinaryToString(StringToBinary($string, 4), 1) & @CRLF)
EndFunc   ;==>_ConsoleOut

; User's COM error function. Will be called if COM error occurs
Func _ErrFunc($oError)
    ; Do anything here.
    _ConsoleOut(@ScriptName & " (" & $oError.scriptline & ") : ==> COM Error intercepted !" & @CRLF & _
            @TAB & "err.number is: " & @TAB & @TAB & "0x" & Hex($oError.number) & @CRLF & _
            @TAB & "err.windescription:" & @TAB & $oError.windescription & @CRLF & _
            @TAB & "err.description is: " & @TAB & $oError.description & @CRLF & _
            @TAB & "err.source is: " & @TAB & @TAB & $oError.source & @CRLF & _
            @TAB & "err.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _
            @TAB & "err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _
            @TAB & "err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _
            @TAB & "err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _
            @TAB & "err.retcode is: " & @TAB & "0x" & Hex($oError.retcode) & @CRLF & @CRLF)
EndFunc   ;==>_ErrFunc

 

I tried this

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...