FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour VIES check 2023
Posts: 1487
Joined: Tue Jun 14, 2016 07:51 AM
VIES check 2023
Posted: Thu Aug 10, 2023 07:32 AM

Has anyone, hoping for a Belgium forum member connected to the VIES system in order to retrieve data from the VIES system by the VAT-number ?

Early postings seems to be outdated with the connections made at that time.

Marc Venken

Using: FWH 23.08 with Harbour
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: VIES check 2023
Posted: Thu Aug 10, 2023 07:47 AM
Dear Marc,

chatgpt response, not sure if it may help:
Code (fw): Select all Collapse
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <curl/curl.h>

// Callback function to receive HTTP response data
size_t WriteCallback(void *contents, size_t size, size_t nmemb, void *userp) {
    size_t realsize = size * nmemb;
    char *response = (char *)userp;

    // Append the received data to the response buffer
    memcpy(response, contents, realsize);
    return realsize;
}

int main(void) {
    CURL *curl;
    CURLcode res;

    curl_global_init(CURL_GLOBAL_DEFAULT);

    curl = curl_easy_init();
    if (curl) {
        char url[200];  // Adjust buffer size if necessary
        char vatNumber[20];  // The VAT number you want to check
        char responseBuffer[1024];  // Buffer to store the response data

        // Construct the URL for VIES VAT number validation
        sprintf(url, "http://ec.europa.eu/taxation_customs/vies/vatResponse.html?&memberStateCode=&number=%s&traderName=&traderCompanyType=&traderStreet=&traderPostcode=&traderCity=&requesterMemberStateCode=&requesterNumber=&action=check&check=Verify",
                vatNumber);

        // Set the URL
        curl_easy_setopt(curl, CURLOPT_URL, url);

        // Set the write callback function to handle the response data
        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
        curl_easy_setopt(curl, CURLOPT_WRITEDATA, responseBuffer);

        // Perform the HTTP request
        res = curl_easy_perform(curl);

        if (res != CURLE_OK) {
            fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
        } else {
            // Print the received response
            printf("Response:\n%s\n", responseBuffer);
        }

        // Cleanup
        curl_easy_cleanup(curl);
    }

    curl_global_cleanup();
    return 0;
}
regards, saludos

Antonio Linares
www.fivetechsoft.com

Continue the discussion