mLipok

VIES over SOAP

10 posts in this topic

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:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for 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 API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF *

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 * Best coding practices * 

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) * 

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 *

"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: 2017-06-04

Share this post


Link to post
Share on other sites



#3 ·  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:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for 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 API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF *

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 * Best coding practices * 

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) * 

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 *

"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: 2017-06-04

Share this post


Link to post
Share on other sites

#4 ·  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

Share this post


Link to post
Share on other sites

What uf_parse_string function doing ?


Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for 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 API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF *

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 * Best coding practices * 

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) * 

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 *

"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: 2017-06-04

Share this post


Link to post
Share on other sites

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:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for 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 API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF *

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 * Best coding practices * 

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) * 

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 *

"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: 2017-06-04

Share this post


Link to post
Share on other sites

#8 ·  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

Share this post


Link to post
Share on other sites

#9 ·  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:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for 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 API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF *

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 * Best coding practices * 

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) * 

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 *

"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: 2017-06-04

Share this post


Link to post
Share on other sites

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&#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)

    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

 


Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for 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 API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF *

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 * Best coding practices * 

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) * 

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 *

"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: 2017-06-04

Share this post


Link to post
Share on other sites

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

  • Similar Content

    • jandings
      By jandings
      Hello there,
      I'm trying to query a REST API of a webservice, SHOPWARE to be precise. The API is very well documented (https://developers.shopware.com/developers-guide/rest-api/#using-the-rest-api-in-your-own-a) but only using PHP. I tried some stuff but could not make it work.
      It should be very simple, because the following simply works in a Chrome-Browser:
      https://USERNAME:PASSPHRASE@www.SHOPWAREDOMAIN.com/api/orders/300
      queries me for username and passphrase and then dumps order number 300.
      Now I try to do the same in AutoIt (based on the wonderful work of many contributors here):
      #include-once #include "..\INCLUDE\winhttp.au3" #include "..\INCLUDE\OO_JSON.au3" ;Proxy Config Global $oJSON = _OO_JSON_Init() Global $obj = "" Global $sUserName = "USERNAME" Global $sPassword = "PASSPHRASE" Global $sDomain = "www.SHOPWAREDOMAIN.com/api/orders/300" Global $hOpen = _WinHttpOpen("Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) JOC/0.1") ; without ie proxy settings $hConnect = _WinHttpConnect($hOpen, "https://" & $sDomain) ConsoleWrite ($hConnect & "#") $sReturned = _WinHttpSimpleSSLRequest($hConnect, "GET", $sUserName & ":" & $sPassword & "@" & $sDomain, Default ) ;$sReturned = _WinHttpSimpleSSLRequest($hConnect, "GET", $sDomain, Default, $sUserName & ":" & $sPassword) ;$sReturned = _WinHttpSimpleSSLRequest($hConnect, "GET", $sDomain, Default, , $sUserName & ":" & $sPassword ) _WinHttpCloseHandle($hConnect) _WinHttpCloseHandle($hOpen) ; See what's returned ConsoleWrite ($sReturned & "#" & @error) Whatever version I use (I tried the commented ones and many others), I always get a reply from Shopware:
      {"success":false,"message":"Invalid or missing auth"}
      At least this comes from Shopware. But there must be some format of the credentials that I don't know or understand.
      Any help?
    • Moxom160
      By Moxom160
      Hello
      First i want to say that most of my problems i can solve while scripting by looking at the forum or in the help file but im stuck on this specific problem. I have been writing scripts to consume Web services and this works fine when its just plain XML responses. I work on a project now where i need to consume a SOAP response with an Attachment. I can make the plain SOAP call and get a response as well but i dont know how to handle the multipart and binary data. I have tried ADODB.Stream to write the data to a file but this just writes everything. I would be very grateful if someone could point me into the right direction.
      Please find below the Request and the Response i get at the momen
       
      $objHTTP = ObjCreate("Microsoft.XMLHTTP") $objReturn = ObjCreate("Msxml2.DOMDocument.3.0") $oDATA=ObjCreate("ADODB.Stream") $strEnvelope = '<?xml version="1.0" encoding="UTF-8"?>' _ '<soapenv:Envelope' _ 'xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"' _ 'xmlns:xsd="http://www.w3.org/2001/XMLSchema"' _ 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">' _ '<soapenv:Body>' _ '<ns1:getStorageAccessTicket' _ 'soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"' _ 'xmlns:ns1="NBRStorageService">' _ '<siteId xsi:type="xsd:long">123456</siteId>' _ '<username xsi:type="xsd:string">USERNAME</username>' _ '<password xsi:type="xsd:string">PASSWORD</password>' _ '</ns1:getStorageAccessTicket>' _ '</soapenv:Body>' '</soapenv:Envelope>' _ ; Set up to post to the server $objHTTP.open ("post", "API end point" , False) ; Set a standard SOAP/ XML header for the content-type $objHTTP.setRequestHeader ("Content-Type", "application/xml") ; Set a header for the method to be called $objHTTP.setRequestHeader ("SOAPAction", 'getStorageAccessTicket') ConsoleWrite("Content of the Soap envelope :" & @CR & $strEnvelope & @CR & @CR ) ; Make the SOAP call $objHTTP.send ($strEnvelope) ; Get the return envelope $strReturn = $objHTTP.responsetext With $oDATA .Type=1 .Open .Write($objHTTP.ResponseBody) .SaveToFile(@ScriptDir&'\captcha.arf', 2) .Close EndWith EndFunc RESPONSE: '------=_Part_5_987625235.1444159091234' 'Content-Type: text/xml; charset=UTF-8' 'Content-Transfer-Encoding: binary' 'Content-Id: <DF72463F6FAFE80B930059E761DF7225>' '<?xml version="1.0" encoding="UTF-8"?>' '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">' '<soapenv:Body>' '<ns1:downloadNBRStorageFileResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="NBRStorageService">' '<ns1:downloadNBRStorageFileReturn xsi:type="soapenc:Array" soapenc:arrayType="ns1:DataHandler[2]" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">' '<item href="cid:FE782065C11E6558C9C8925EBE3D687F"/>' '<item href="cid:3CF0B37E4C5932A3E60EBA5226CFC30A"/>' '</ns1:downloadNBRStorageFileReturn>' '</ns1:downloadNBRStorageFileResponse>' '</soapenv:Body>' '</soapenv:Envelope>' ------=_Part_5_987625235.1444159091234 Content-Type: application/octet-stream Content-Transfer-Encoding: binary Content-Id: <FE782065C11E6558C9C8925EBE3D687F> Attachment.arf 2342371 false ------=_Part_5_987625235.1444159091234 Content-Type: application/octet-stream Content-Transfer-Encoding: binary Content-Id: <3CF0B37E4C5932A3E60EBA5226CFC30A>