Quantcast
Channel: Active questions tagged rest - Stack Overflow
Viewing all articles
Browse latest Browse all 3667

Delphi RestClient on Mac and Windows

$
0
0

I have server (WebBroker) and client (RestClient) applications. The server is executed on Windows, and one of its methods looks like this:

procedure TWM.KlijentiFirmeGet(Request: TWebRequest; Response: TWebResponse);var  Sve       : Boolean;  FirmaID   : String;  firme     : TFirme_Klijenti;begin  try    Sve       := Request.QueryFields.Values['sve'].ToBoolean;  except    Sve       := False;  end;  try    FirmaID   := Request.QueryFields.Values['firmaID'];  except    FirmaID   := EmptyStr;  end;  firme   := TFirme_Klijenti.Create;  try    Response.ContentType  := 'application/json; charset=utf-8';    if Sve then      Response.Content    :=  Firme.PreuzmiSveFirme.ToJSON    else      Response.Content    :=  Firme.PreuzmiFirmu(FirmaID).ToJSON;  finally    firme.Free;  end;  Response.StatusCode := 200;end;

Returning value of the Firme.PreuzmiSveFirme method is in TJSONArray format.

On the client side, calling the method looks like this:

function TConnection.IzvrsiAkciju(params: TJSONObject): TJSONValue; safecall;var  ini : TIniFile;  adresa : string;  port   : Integer;  putanja: string;  metod  : Integer; //0 - get, 1 - POST, 2 - PUT, 3 - Delete  header : TJSONArray;  JV     : TJSONValue;  str   : string;  kljuc, vrednost : string;begin  var RESTClient        := TRESTClient.Create(nil);  var RESTResponse      := TRESTResponse.Create(nil);  var RESTRequest       := TRESTRequest.Create(nil);  try    RESTClient.ConnectTimeout   := 300000;  // TODO -cMM : Interface wizard: Implement interface method    Result  := TJSONObject.create;    ini:=TIniFile.Create(ChangeFileExt(ParamStr(0), '.ini'));    adresa := ini.ReadString('Server', 'adresa', 'http://192.168.0.33');    port:=ini.ReadInteger('Server', 'port', 211);    RESTClient.BaseURL    := Adresa +':'+ port.ToString;    RESTRequest.Client    := RESTClient;    RESTRequest.Response  := RESTResponse;    RESTRequest.Resource  :=params.GetValue<string>('putanja', '');    metod:=params.GetValue<Integer>('metod', 0);    header:=params.GetValue<TJSONArray>('header', TJSONArray.Create);    case metod of      0 : //Get        begin          str  := '';          RESTRequest.Method    := rmGET;          for jv in header do          begin            kljuc     := TJSONObject(JV).GetValue<string>('kljuc', '');            vrednost  := TJSONObject(JV).GetValue<string>('vrednost', '');            RESTRequest.AddParameter(kljuc, Vrednost);          end;          RESTRequest.Execute;          try            str := Trim(RestResponse.Content);            Result  := TJSONObject.ParseJSONValue(RestResponse.Content) as TJSONArray;          except            Result  := TJSONArray.Create;          end;        end;      1 : ;    else ;    end;  finally  end;end;

When I execute the client on Windows, RestResponse.Content contains the whole JSONArray (converted to string). But, on MacOS, RestResponse.Content contains only [{ letters.

What I am doing wrong?

Delphi version is 12.1.


Viewing all articles
Browse latest Browse all 3667

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>