Help to convert code in Indy lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- laguna · 2022-11-28 17:17 I ask you for help in converting this XML file submission procedure to lazarus using its components. The program must work on Linux and Mac and I cannot make use of paid DLLs since the submission program is a free product. You can help me thanks. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i  procedure TForm1.Button1Click(Sender: TObject);varhttp: HCkHttp;success: Boolean;sbSignedXml: HCkStringBuilder;json: HCkJsonObject;resp: HCkHttpResponse;sbResponseBody: HCkStringBuilder;jResp: HCkJsonObject;respStatusCode: Integer;errorCode: PWideChar;errorDescription: PWideChar;requestID: PWideChar; begin// This example assumes the Chilkat API to have been previously unlocked.// See Global Unlock Sample for sample code. http := CkHttp_Create(); // Implements the following CURL command: // curl -X POST https://auth.fatturazioneelettronica.aruba.it/services/ClientRequ est/CreateTransmissionRequest \//   -H "Accept: application/json" \// -H "Content-Type: application/json;charset=UTF-8" \//   -d '{//   "userName" : "ARUBA0000",//   "password" : "ArubaPwd",//   "userID" : "ARUBA0000",//   "comunicationType" : "LI",//   "dataFile" : "dGVzdA=="// }' // Use the following online tool to generate HTTP code from a CURL command// Convert a cURL Command to HTTP Source Code // Use this online tool to generate code from sample JSON:// Generate Code to Create JSON // The following JSON is sent in the request body. // {//   "userName": "ARUBA0000",//   "password": "ArubaPwd",// "userID": "ARUBA0000",//   "comunicationType": "LI",//   "dataFile": "dGVzdA=="// } // The dataFile field must contain an xml document which conforms to the Revenue Agency specifications.// The document must be Base64 codified and contain a CADES-based electronic signature.sbSignedXml := CkStringBuilder_Create();success := CkStringB uilder_LoadFile(sbSignedXml,'IT01873080855_00310.xml','utf-8'); json := CkJsonObject_Create();CkJsonObject_UpdateString(json,'userName','AR UBA0000');CkJsonObject_UpdateString(json,'password','ArubaPwd');CkJson Object_UpdateString(json,'userID','ARUBA0000');CkJsonObject_UpdateStri ng(json,'comunicationType','LI');CkJsonObject_UpdateString(json,'dataF ile',CkStringBuilder__getEncoded(sbSignedXml,'base64','utf- 8')); CkHttp_SetRequestHeader(http,'Content-Type','application/json;ch arset=UTF- 8');CkHttp_SetRequestHeader(http,'Accept','application/json'); resp := CkHttp_PostJson3(http,'https://ws.fatturazioneelettronica.aruba.it/ser vices/ClientRequest/CreateTransmissionRequest','application/json',json );if (CkHttp_getLastMethodSuccess(http) = False) then  begin    Memo1.Lines.Add(CkHttp__lastErrorText(http));    Exit;  end; sbResponseBody := CkStringBuilder_Create();CkHttpResponse_GetBody Sb(resp,sbResponseBody);jResp := CkJsonObject_Create();CkJsonObject_Lo adSb(jResp,sbResponseBody);CkJsonObject_putEmitCompact(jResp,False); M emo1.Lines.Add('Response Body:');Memo1.Lines.Add(CkJsonObject__emit(jResp)); respStatusCode := CkHttpResponse_getStatusCode(resp);Memo1.Lines.Add('Response Status Code = ' + IntToStr(respStatusCode));if (respStatusCode >= 400) then  begin    Memo1.Lines.Add('Response Header:');    Memo1.Lines.Add(CkHttpResponse__header(resp));    Memo1.Lines.Add('Failed.');    CkHttpResponse_Dispose(resp);    Exit;  end;CkHttpResponse_Dispose(resp); // Sample JSON response:// (Sample code for parsing the JSON response is shown below) // {//   "errorCode": "",//   "errorDescription": "",//   "requestID": "UICBY9QDLUOXQ72U"// } // Sample code for parsing the JSON response...// Use the following online tool to generate parsing code from sample JSON:// Generate Parsing Code from JSON errorCode := CkJsonObject__stringOf(jResp,'errorCode');errorDescription := CkJsonObject__stringOf(jResp,'errorDescription');requestID := CkJsonOb ject__stringOf(jResp,'requestID'); CkHttp_Dispose(http);CkStringBuilde r_Dispose(sbSignedXml);CkJsonObject_Dispose(json);CkStringBuilder_Disp ose(sbResponseBody);CkJsonObject_Dispose(jResp); end; ---------------------------------------------------------------------- Remy Lebeau · 2022-11-28 19:28 Quote from: laguna on November 28, 2022, 06:17:51 pmI ask you for help in converting this XML file submission procedure to lazarus using its components. If you are asking how to rewrite that code to use TIdHTTP, then it would look something like this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses  Classes, IdHTTP, IdCoderMIME, fpjson, jsonparser; procedure TForm1.Button1Click(Sender: TObject);var  http: TIdHTTP;  success: Boolean;  sSignedXml: string;  json: string;  sResponseBody: string;  respStatusCode: Integer;  jData: TJSONData;  jObject: TJSONObject;  errorCode: string;  errorDescription: string;  requestID: string;  FS: TFileStream;  SS: TStringStream;begin  http := TIdHTTP.Create;  try  // Implements the following CURL command:     // curl -X POST https:// auth.fatturazioneelettronica.aruba.it/services/ClientRequest/CreateTra nsmissionRequest \    //   -H "Accept: application/json" \    //   -H "Content-Type: application/json;charset=UTF-8" \    //   -d '{    // "userName" : "ARUBA0000",    //   "password" : "ArubaPwd",    //   "userID" : "ARUBA0000",    //   "comunicationType" : "LI",    //   "dataFile" : "dGVzdA=="    // }'     // Use the following online tool to generate HTTP code from a CURL command    // Convert a cURL Command to HTTP Source Code     // Use this online tool to generate code from sample JSON:    // Generate Code to Create JSON     // The following JSON is sent in the request body.     // {    //   "userName": "ARUBA0000",    //   "password": "ArubaPwd",    //   "userID": "ARUBA0000",    //   "comunicationType": "LI",    //   "dataFile": "dGVzdA=="    // }     // The dataFile field must contain an xml document which conforms to the Revenue Agency specifications.    // The document must be Base64 codified and contain a CADES-based electronic signature.     FS := TFileStream.Create('IT01873080855_00310.xml', fmOpenRead or fmShareDenyWrite);    try      sSignedXml := TIdEncoderMIME.EncodeStream(FS);    finally      FS.Free;    end;     jObject := TJSONObject.Create;    try      jObject.Add('userName', 'ARUBA0000');      jObject.Add('password', 'ArubaPwd');      jObject.Add('userID', 'ARUBA0000');      jObject.Add('comunicationType', 'LI');      jObject.Add('dataFile', sSignedXml);      json := jObject.AsJSON;    finally      jObject.Free;    end;     http.Request.ContentType := 'application/json';    http.Request.CharSet := 'UTF-8';    http.Request.Accept := 'application/json';     http.HTTPOptions := http.HTTPOptions + [hoNoProtocolErrorException, hoWantProtocolErrorContent];     SS := TStringStream.Create(json);    try      sResponseBody := http.Post('https://ws.fatturazioneelettronic a.aruba.it/services/ClientRequest/CreateTransmissionRequest', SS);    finally      SS.Free;    end;     Memo1.Lines.Add('Response Body:');  Memo1.Lines.Add(sResponseBody);     respStatusCode := http.Response.ResponseCode;    Memo1.Lines.Add('Response Status Code = ' + IntToStr(respStatusCode));    if (respStatusCode >= 400) then    begin      Memo1.Lines.Add('Response Header:');      Memo1.Lines.Add(http.Response.RawHeaders.Text);      Memo1.Lines.Add('Failed.');      Exit;    end;     // Sample JSON response:    // (Sample code for parsing the JSON response is shown below)     // {    //   "errorCode": "",    //   "errorDescription": "",    //   "requestID": "UICBY9QDLUOXQ72U"    // }     // Sample code for parsing the JSON response...    // Use the following online tool to generate parsing code from sample JSON:    // Generate Parsing Code from JSON     jData := GetJSON(sResponseBody);    try      jObject := jData as TJSONObject;      errorCode := jObject.Get('errorCode');    errorDescription := jObject.Get('errorDescription');      requestID := jObject.Get('requestID');    finally      jData.Free;    end;  finally    http.Free;  end;end; ---------------------------------------------------------------------- laguna · 2022-11-29 12:44 it's work, now implement program and i will publish in github thanks a lot