Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
API BindCommerce
#1
Hi,
I need to connect a application (delphi 11) with API web service of bindcommerce (https://www.bindcommerce.com/it/guide/ap...t-prodotti)

this is an examples in php of autentication:

<?php
ini_set('display_errors', true);
error_reporting(E_ALL);


$strXml = file_get_contents(__DIR__.'/Products.xml');

$curl = curl_init();
curl_setopt_array($curl, array(


CURLOPT_URL => "https://miohost.bindcommerce.cloud/integrator-tool/api/products.php?connector=N",
CURLOPT_SSL_VERIFYPEER => 0,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_VERBOSE => true,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => $strXml,
CURLOPT_HTTPHEADER => array(

"cache-control: no-cache",

"content-type: text/xml",

"token: 0435a03b361d7cc24fc1acacdeaae1d7"

),
));

$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}

How in delphi ?
thanks
Reply
#2
(04-20-2022, 11:16 AM)staff@ergosoft.it Wrote: this is an examples in php of autentication:
...
How in delphi ?

Something like this:

Code:
uses
  ..., Classes, IdGlobal, IdHTTP, IdSSLOpenSSL;
  
var
  http: TIdHTTP;
  ssl: TIdSSLIOHandlerSocketOpenSSL;
  postData: TStream;
  response: String;
begin
  try
    // alternatively, you can configure these components at design-time instead...
    http := TIdHTTP.Create(nil);
    try
      http.HTTPOptions := http.HTTPOptions + [hoKeepOrigProtocol];
      http.ProtocolVersion := pv1_1;
      http.ReadTimeout := 30000;
      http.RedirectMaximum := 10;

      http.Request.CacheControl := 'no-cache';
      http.Request.ContentType := 'text/xml';
      http.Request.CustomHeaders.Values['token'] := '0435a03b361d7cc24fc1acacdeaae1d7';

      ssl := TIdSSLIOHandlerSocketOpenSSL.Create(http);
      ssl.SSLOptions.SSLVersions := [sslvTLSv1, sslvTLSv1_1, sslvTLSv1_2];
      ssl.VerifyMode := [];
      ssl.VerifyDepth := 0;
      http.IOHandler := ssl;
      
      postData := TIdReadFileExclusiveStream.Create('<path to>\Products.xml');
      try
        response := http.Post('https://miohost.bindcommerce.cloud/integrator-tool/api/products.php?connector=N', postData);
      finally
        postData.Free;
      end;
    finally
      http.Free;
    end;

    // use response as needed...
  except
    on E: Exception do
      // use E as needed...
  end;
end;

Reply
#3
Hi rlebeau,
thanks very much !

it works !!!

I have only error on

ssl.VerifyMode := [];
ssl.VerifyDepth := 0;

undeclared identifier (verifymode and verifydeph)...
I remove this 2 lines and work...

probabily for my ssl version ? ....

thanks

Alessandro Romano
Reply
#4
(04-20-2022, 04:35 PM)staff@ergosoft.it Wrote: I have only error on

ssl.VerifyMode := [];
ssl.VerifyDepth := 0;

undeclared identifier (verifymode and verifydeph)...

Sorry, that should have been:

Code:
ssl.SSLOptions.VerifyMode := [];
ssl.SSLOptions.VerifyDepth := 0;

Reply
#5
(04-20-2022, 11:06 PM)rlebeau Wrote:
(04-20-2022, 04:35 PM)staff@ergosoft.it Wrote: I have only error on

ssl.VerifyMode := [];
ssl.VerifyDepth := 0;

undeclared identifier (verifymode and verifydeph)...

Sorry, that should have been:

Code:
ssl.SSLOptions.VerifyMode := [];
ssl.SSLOptions.VerifyDepth := 0;

thanks !
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)