客户端中来自RESTRequest的参数不会传递到服务器-Delphi

时间:2019-03-11 19:07:00

标签: delphi

我没有将RESTRequest中的参数从客户端传递到服务器,当我检查服务器端的参数时,它们都是空的。

  // Configurando REST Client
  ...
  RESTClient1.Accept := 'application/json, text/plain; q=0.9, text/html;q=0.8,';
  RESTClient1.AcceptCharset := 'UTF-8, *;q=0.8';
  RESTClient1.BaseURL := Format('http://%s:%s/datasnap/rest', [IPV4, '8080']);
  RESTClient1.ContentType := 'image/jpeg';
  RESTClient1.HandleRedirects := True;
  RESTClient1.RaiseExceptionOn500 := False;
  RESTRequest1.Client := RESTClient1;

  RESTRequest1.Params.AddItem('AArquivo', 'fotosoon', pkGETorPOST, [poDoNotEncode], ctTEXT_PLAIN);
  RESTRequest1.Params.AddItem('Pasta', 'teste', pkGETorPOST, [poDoNotEncode], ctTEXT_PLAIN);
  RESTRequest1.Params.AddItem('Size', StrSize.ToString, pkGETorPOST, [poDoNotEncode], ctTEXT_PLAIN);
  RESTRequest1.Params.AddItem('ASetStream', fStream, TRESTRequestParameterKind.pkREQUESTBODY,
    [poDoNotEncode],
    ctIMAGE_JPEG);

  RESTRequest1.Resource := 'TServerMethods1/UploadFile';
  RESTRequest1.Response := RESTResponse1;
  RESTRequest1.SynchronizedEvents := False;
  RESTRequest1.Execute;

我尝试以其他方式发送参数,包括:

RESTRequest1.AddParameter('AArquivo', 'filename');

在服务器端,所有四个参数均为空,我唯一可以成功传递参数的方法是将其放在url中。

RESTClient1.BaseURL := Format('http://%s:%s/datasnap/rest', [IPV4, '8080']);
RESTClient1.BaseURL := RESTClient1.BaseURL + '/TServerMethods1/UploadFile';
RESTClient1.BaseURL := RESTClient1.BaseURL + '/fotosoon/teste/' + StrSize.ToString;

通过这种方式,三个参数值正确到达服务器端,但是,它缺少fStream: TStream参数,该参数无法在url中传递。

0 个答案:

没有答案