Tema: post a web
Ver Mensaje Individual
  #29  
Antiguo 17-05-2023
Avatar de oscarac
[oscarac] oscarac is offline
Miembro Premium
 
Registrado: sep 2006
Ubicación: Lima - Perú
Posts: 2.010
Reputación: 20
oscarac Va por buen camino
al final cambié a Indy.... y funcionó

les dejo el codigo por si alguien lo necesita

Código Delphi [-]
unit frmMain_f;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
  System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs,
  IdMultipartFormData, IdSSLOpenSSL, IdSSLOpenSSLHeaders, Vcl.StdCtrls,
  IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient, IdHTTP,
  IdIOHandler, IdIOHandlerSocket, IdIOHandlerStack, IdSSL, system.json;

type
  TForm1 = class(TForm)
    IndCredenciales: TIdHTTP;
    Button1: TButton;
    Memo1: TMemo;
    Label1: TLabel;
    IndCredencialesSSL: TIdSSLIOHandlerSocketOpenSSL;
    Memo2: TMemo;
    IndFile: TIdHTTP;
    IndFileSSL: TIdSSLIOHandlerSocketOpenSSL;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
  //lHTTP: TIdHTTP;
  datosPost: TIdMultiPartFormDataStream;
  URL: string;
  response, tk, localfile: string;
  respuesta: TJSONValue;
  RequestBody: TStream;

begin
 localfile := 'd:\desarrollo\concesiones\servicial\aris\envios\LURIN-09052023.txt';
  try

    //Conexion Endpoint Primario
    URL := 'https://zona-api.aris.com.pe/v1/user/signin';


    datosPost := TIdMultiPartFormDataStream.Create;
    datosPost.AddFormField('user', 'user');
    datosPost.AddFormField('password', '***********');
    response := IndCredenciales.Post(URL, datosPost);
    Memo1.Text := response;
    respuesta := TJSonObject.ParseJSONValue(response);
    tk := respuesta.GetValue<string>('data.data.tk');
    Label1.Caption := tk;
    datosPost.Free;
    // Ya estoy conectado

    // Conexion EndPoint Archivo
    // enviar archivo
    URL := 'https://zona-api.aris.com.pe/v1/concesionario/masivo';
    IndFile.Request.CustomHeaders.FoldLines := False;
    indFile.Request.CustomHeaders.Add('Authorization:Bearer ' + tk);
    datosPost := TIdMultiPartFormDataStream.Create;
    datosPost.AddFile('archivo', localfile, 'multipart/form-data');
    Response := IndFile.Post(URL, datosPost);
    Memo2.Text := response;
    datosPost.Free;

  finally
  end;
end;


end.
__________________
Dulce Regalo que Satanas manda para mi.....
Responder Con Cita