Dmytro Lendel 1 Posted July 25, 2020 Hello, I changed a little simple OverbyteIcsThrdSrvV2_1 I need create dynamic http request in processdata event and send answer to Client procedure TTcpSrvForm.ProcessData(Client : TThrdSrvClient); Err:String; begin if Copy(Trim(Client.RcvdLine),1,3)='$RQ' then begin Err:=''; HttpPostByStr('{"serialNumber":"98D863E0F226","state":"No data for you"}',Err); Display(IntToHex((Client as TThrdSrvClient).ThreadID,8)+' '+ err); end; end; function HttpPostByStr(SJson: String;var Resp:String):Boolean; var FIDHttp:THttpCli; JsonToSend: TStringStream; ResivdToSend: TStringStream; MyResp,get_url: string; begin Result:=False; MyResp:=''; get_url:='http://194.44.237.46:8087'+'/api/points/states'; JsonToSend := TStringStream.Create('['+SJson+']', TEncoding.UTF8); JsonToSend.Position := 0; ResivdToSend:=TStringStream.Create; FIDHttp:=THttpCli.Create(nil); FIDHttp.ContentTypePost := 'application/json-patch+json'; FIDHttp.Username:='username'; FIDHttp.Password:='pass'; FIDHttp.serverauth:=httpAuthBasic; FIDHttp.URL:=get_url; FIDHttp.SendStream:=JsonToSend; FIDHttp.RcvdStream:=ResivdToSend; Resp:=''; try try FIDHttp.Post; Result:=True; except on E: Exception do begin Resp:= e.Message; end; end; finally ResivdToSend.Seek(0, 0); //Resp='' then Resp:=ResivdToSend.DataString; ResivdToSend.Free; JsonToSend.Free; FIDHttp.Free; end; end; It`s working, but after closing application exception in OverbyteIcsWSocket "Invalid pointer operation" destructor TCustomLineWSocket.Destroy; begin if FRcvdPtr <> nil then begin FreeMem(FRcvdPtr, FRcvBufSize); <-- here FRcvdPtr := nil; FRcvBufSize := 0; end; inherited Destroy; end; Where is my mistake? Regards Dmytro Share this post Link to post
Dmytro Lendel 1 Posted July 26, 2020 Hello, Problem after calling function HttpPostByStr Next line from client generate exception Invalid point operation and after some time server is crashing I can`t to understand why. Regards, Dmytro Share this post Link to post