Tema: post a web
Ver Mensaje Individual
  #26  
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
buenos dias
tengo una respuesta del servidoer indicando que el archivo esta vacio
esa respuesta me da, cuando no envio el archivo, porque si lo recibe la respuesta seria otra

mi restdebugger no esta funcionando, aparece un mensaje de error

ahora.. en postman en el body, el parametro llamado "archivo" es de tipo file... hay tipo texto tambien, pero con ese no funciona, debe ser tipo file...... creo que por ahi va la cosa...

esto es lo que tengo

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,
  IPPeerClient, Vcl.StdCtrls, REST.Client, Data.Bind.Components,
  Data.Bind.ObjectScope, system.JSON, REST.Authenticator.OAuth, REST.Types;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Memo1: TMemo;
    Label1: TLabel;
    RCCredenciales: TRESTClient;
    RQCredenciales: TRESTRequest;
    RRCredenciales: TRESTResponse;
    Label2: TLabel;
    Memo2: TMemo;
    RRFile: TRESTResponse;
    RQFile: TRESTRequest;
    RCFile: TRESTClient;
    oAUTHRQ: TOAuth2Authenticator;
    procedure Button1Click(Sender: TObject);
  private
    function MemoryStreamToString(M: TMemoryStream): string;
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
  jValue: TJSONValue;  // Respuesta del Request
  JSonValue: TJSonValue;
  Branch: string;
  _file: TMemoryStream;
  localfile: string;
  param: TRESTRequestParameter;
begin
  localfile := 'd:\desarrollo\concesiones\servicial\aris\envios\LURIN-09052023.txt';

  try
    // CLiente
    RCCredenciales.ResetToDefaults;
    RCCredenciales.BaseURL := 'https://zona-api.aris.com.pe/v1/user/signin';
    RCCredenciales.Accept := 'application/json, text/plain; q=0.9, text/html;q=0.8,';
    RCCredenciales.AddParameter('user', 'user');
    RCCredenciales.AddParameter('password', '******************');

    // Request
    RQCredenciales.Method := TRESTRequestMethod.rmPOST;
    RQCredenciales.Execute;

    // Ya se conectó a la web

    jValue := RRCredenciales.JSONValue;
    Branch := jValue.ToString;
    JSonValue := TJSonObject.ParseJSONValue(Branch);

    // Chapo El Token y lo coloco en el Auth2
    oAUTHRQ.AccessToken := JSonValue.GetValue<string>('data.data.tk');
    oAUTHRQ.TokenType := TOAuth2TokenType.ttBEARER;
    Memo1.Text := Branch;

    RCFile.ResetToDefaults;
    RCFile.Params.Clear;
    RCFile.BaseURL := 'https://zona-api.aris.com.pe/v1/concesionario/masivo';
    RCFile.Accept := 'text/plain';
    RCFile.Authenticator := oAUTHRQ;

    //RQFile.ClearBody;
    RQFile.Method := TRESTRequestMethod.rmPOST;

    _file := TMemoryStream.Create();
    _file.LoadFromFile(localfile);
    _file.Position := 0;


    param := RQFile.Params.AddItem;
    RQFile.Params[0].name := 'archivo';
    RQFile.Params[0].value := MemoryStreamToString(_file);
    RQFile.Params[0].kind := pkGETorPOST;
    RQFile.Params[0].ContentType := ctTEXT_PLAIN;
    RQFile.Params[0].Options := [poDoNotEncode];

    RQFile.Execute;
    jValue := RRFile.JSONValue;
    Memo2.Text := jValue.ToString;

  finally

  end;
end;

function TForm1.MemoryStreamToString(M: TMemoryStream): string;
begin
  SetString(Result, PChar(M.Memory), M.Size div SizeOf(Char));
end;

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