Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Unicode C) Magyar Nemzeti Bank (MNB) Get CurrenciesThe Magyar Nemzeti Bank (MNB) is the central bank of Hungary. In this role, its primary objective is to achieve and maintain price stability. The MNB website is available to visitors in both Hungarian and English. The MNB provides the Arfolyam (trans. Exchange Rate) API, which can be used to retrieve current and historic currency exchange rates. This service uses SOAP calls issued in XML format. This example gets a list of currencies.
#include <C_CkRestW.h> #include <C_CkXmlW.h> #include <C_CkStringBuilderW.h> void ChilkatSample(void) { HCkRestW rest; BOOL success; BOOL bTls; int port; BOOL bAutoReconnect; HCkXmlW xml; HCkStringBuilderW sbRequestBody; HCkStringBuilderW sbResponseBody; int respStatusCode; HCkXmlW xmlResponse; const wchar_t *resultEncoded; HCkStringBuilderW sbResult; HCkXmlW xmlResult; rest = CkRestW_Create(); // URL: http://www.mnb.hu/arfolyamok.asmx bTls = FALSE; port = 80; bAutoReconnect = TRUE; success = CkRestW_Connect(rest,L"www.mnb.hu",port,bTls,bAutoReconnect); if (success != TRUE) { wprintf(L"ConnectFailReason: %d\n",CkRestW_getConnectFailReason(rest)); wprintf(L"%s\n",CkRestW_lastErrorText(rest)); CkRestW_Dispose(rest); return; } // -------------------------------------------------------------------------------- // Also see Chilkat's Online WSDL Code Generator // to generate code and SOAP Request and Response XML for each operation in a WSDL. // -------------------------------------------------------------------------------- xml = CkXmlW_Create(); CkXmlW_putTag(xml,L"soapenv:Envelope"); CkXmlW_AddAttribute(xml,L"xmlns:soapenv",L"http://schemas.xmlsoap.org/soap/envelope/"); CkXmlW_AddAttribute(xml,L"xmlns:web",L"http://www.mnb.hu/webservices/"); CkXmlW_UpdateChildContent(xml,L"soapenv:Header",L""); CkXmlW_UpdateChildContent(xml,L"soapenv:Body|web:GetCurrencies",L""); CkRestW_AddHeader(rest,L"Content-Type",L"text/xml"); CkRestW_AddHeader(rest,L"SOAPAction",L"/webservices/MNBArfolyamServiceSoap/GetCurrencies"); CkRestW_AddHeader(rest,L"Accept",L"application/xml"); sbRequestBody = CkStringBuilderW_Create(); CkXmlW_GetXmlSb(xml,sbRequestBody); sbResponseBody = CkStringBuilderW_Create(); success = CkRestW_FullRequestSb(rest,L"POST",L"/arfolyamok.asmx",sbRequestBody,sbResponseBody); if (success != TRUE) { wprintf(L"%s\n",CkRestW_lastErrorText(rest)); CkRestW_Dispose(rest); CkXmlW_Dispose(xml); CkStringBuilderW_Dispose(sbRequestBody); CkStringBuilderW_Dispose(sbResponseBody); return; } respStatusCode = CkRestW_getResponseStatusCode(rest); if (respStatusCode >= 400) { wprintf(L"Response Status Code = %d\n",respStatusCode); wprintf(L"Response Header:\n"); wprintf(L"%s\n",CkRestW_responseHeader(rest)); wprintf(L"Response Body:\n"); wprintf(L"%s\n",CkStringBuilderW_getAsString(sbResponseBody)); CkRestW_Dispose(rest); CkXmlW_Dispose(xml); CkStringBuilderW_Dispose(sbRequestBody); CkStringBuilderW_Dispose(sbResponseBody); return; } wprintf(L"response status code = %d\n",respStatusCode); xmlResponse = CkXmlW_Create(); CkXmlW_LoadSb(xmlResponse,sbResponseBody,TRUE); wprintf(L"%s\n",CkXmlW_getXml(xmlResponse)); // The XML response contains this: // <?xml version="1.0" encoding="utf-8" ?> // <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> // <s:Body> // <GetCurrenciesResponse xmlns="http://www.mnb.hu/webservices/" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"> // <GetCurrenciesResult><MNBCurrencies><Currencies><Curr>HUF</Curr><Curr>EUR</Curr><Curr>AUD</Curr> ... </MNBCurrencies></GetCurrenciesResult> // </GetCurrenciesResponse> // </s:Body> // </s:Envelope> // Get the GetCurrenciesResult resultEncoded = CkXmlW_getChildContent(xmlResponse,L"s:Body|GetCurrenciesResponse|GetCurrenciesResult"); wprintf(L"%s\n",resultEncoded); // Entity decode the result to get XML. sbResult = CkStringBuilderW_Create(); CkStringBuilderW_Append(sbResult,resultEncoded); CkStringBuilderW_EntityDecode(sbResult); // Load it into XML. xmlResult = CkXmlW_Create(); CkXmlW_LoadSb(xmlResult,sbResult,TRUE); wprintf(L"%s\n",CkXmlW_getXml(xmlResult)); // The result is this: // <?xml version="1.0" encoding="utf-8" ?> // <MNBCurrencies> // <Currencies> // <Curr>HUF</Curr> // <Curr>EUR</Curr> // <Curr>AUD</Curr> // <Curr>BGN</Curr> // <Curr>BRL</Curr> // <Curr>CAD</Curr> // <Curr>CHF</Curr> // <Curr>CNY</Curr> // <Curr>CZK</Curr> // <Curr>DKK</Curr> // <Curr>GBP</Curr> // <Curr>HKD</Curr> // <Curr>HRK</Curr> // <Curr>IDR</Curr> // <Curr>ILS</Curr> // <Curr>INR</Curr> // <Curr>ISK</Curr> // <Curr>JPY</Curr> // <Curr>KRW</Curr> // <Curr>MXN</Curr> // <Curr>MYR</Curr> // <Curr>NOK</Curr> // <Curr>NZD</Curr> // <Curr>PHP</Curr> // <Curr>PLN</Curr> // <Curr>RON</Curr> // <Curr>RSD</Curr> // <Curr>RUB</Curr> // <Curr>SEK</Curr> // <Curr>SGD</Curr> // <Curr>THB</Curr> // <Curr>TRY</Curr> // <Curr>UAH</Curr> // <Curr>USD</Curr> // <Curr>ZAR</Curr> // <Curr>ATS</Curr> // <Curr>AUP</Curr> // <Curr>BEF</Curr> // <Curr>BGL</Curr> // <Curr>CYN</Curr> // <Curr>CSD</Curr> // <Curr>CSK</Curr> // <Curr>DDM</Curr> // <Curr>DEM</Curr> // <Curr>EEK</Curr> // <Curr>EGP</Curr> // <Curr>ESP</Curr> // <Curr>FIM</Curr> // <Curr>FRF</Curr> // <Curr>GHP</Curr> // <Curr>GRD</Curr> // <Curr>IEP</Curr> // <Curr>ITL</Curr> // <Curr>KPW</Curr> // <Curr>KWD</Curr> // <Curr>LBP</Curr> // <Curr>LTL</Curr> // <Curr>LUF</Curr> // <Curr>LVL</Curr> // <Curr>MNT</Curr> // <Curr>NLG</Curr> // <Curr>OAL</Curr> // <Curr>OBL</Curr> // <Curr>OFR</Curr> // <Curr>ORB</Curr> // <Curr>PKR</Curr> // <Curr>PTE</Curr> // <Curr>ROL</Curr> // <Curr>SDP</Curr> // <Curr>SIT</Curr> // <Curr>SKK</Curr> // <Curr>SUR</Curr> // <Curr>VND</Curr> // <Curr>XEU</Curr> // <Curr>XTR</Curr> // <Curr>YUD</Curr> // </Currencies> // </MNBCurrencies> // CkRestW_Dispose(rest); CkXmlW_Dispose(xml); CkStringBuilderW_Dispose(sbRequestBody); CkStringBuilderW_Dispose(sbResponseBody); CkXmlW_Dispose(xmlResponse); CkStringBuilderW_Dispose(sbResult); CkXmlW_Dispose(xmlResult); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.