Tema: post a web
Ver Mensaje Individual
  #15  
Antiguo 12-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
continuo con mi problema

con esta parte me conecto al endpoint

Código Delphi [-]
  RESTRequest1.Execute;
  jValue := RESTResponse1.JSONValue;
  Memo1.Text := jValue.ToString;
  Branch := jValue.ToString;

  st := Memo1.text;
  JSonValue := TJSonObject.ParseJSONValue(Branch);
  Label1.Caption := JSonValue.GetValue<string>('data.mensaje');
  Label2.Caption := JSonValue.GetValue<string>('data.data.tk');
  OAuth2Authenticator1.AccessToken := JSonValue.GetValue<string>('data.data.tk');

este es el archivo q quiero enviar
localfile := 'd:\desarrollo\concesiones\servicial\aris\envios\LURIN-09052023.txt';

primer intento fallido
Código Delphi [-]
{  jsRequest := TJSONObject.Create();
  jsRequest.AddPair('file', 'archivo');
  jsRequest.AddPair('value', localfile);
  RESTRequest2.AddBody(jsRequest);
 }

segundo intento fallikdo
Código Delphi [-]
RESTRequest2.AddParameter('archivo', localfile, TRESTRequestParameterKind.pkREQUESTBODY);


tercer intento fallido
Código Delphi [-]
//  RESTClient2.Params.AddItem('name', 'file', TRESTRequestParameterKind.pkGETorPOST, [], TRESTContentType.ctMULTIPART_FORM_DATA);
//  RESTClient2.Params.AddItem('archivo', localfile, TRESTRequestParameterKind.pkGETorPOST, [],

cuarto intento fallido
Código Delphi [-]
//st:=('{"archivo": ' + localfile + '}');
//RESTRequest2.AddBody(st);

quinto intento fallido
Código Delphi [-]
{RESTClient2.Params.AddItem; //Adds a new Parameter Item
RESTClient2.Params.Items[0].name := 'archivo'; //sets the name of the parameter. In this case, since i need to use 'data=' on the request, the parameter name is data.
RESTClient2.Params.Items[0].Value := localfile; //Adds the value of the parameter, in this case, the XML data.
RESTClient2.Params.Items[0].ContentType := ctMULTIPART_FORM_DATA; //sets the content type.
RESTClient2.Params.Items[0].Kind := pkGETorPOST; //sets the kind of request that will be executed.
 }
Código Delphi [-]
RESTRequest2.Execute;
Memo2.Lines.Add(RESTResponse2.Content);
JSonValue.Free;

mi razonamiento es el siguiente....
si en postman coloco el archivo en el body (form-data)
el key es "archivo" y el value es el nombre del archivo

el tema es que el archivo es de tipo "file"

creo que casi todo esta bien.... incluso cuando pruebo con postman (sin enviar el archivo o archivo vacio) me devuelve el mismo mensaje que en delphi, parece que solo tengo que descubrir como meter en el body del request los parametros

o será que ya me hice un mundo en la cabeza.. y no puedo ver la solución
__________________
Dulce Regalo que Satanas manda para mi.....
Responder Con Cita