Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / pas2js / 2020-02

Pas2js issue in posting a modified record - TRESTDataProxy

2 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Simone Giacomelli

Dear coders,

I think I found a fix for a problem (?) in the function below.

The problem is that with the code in pas2js 1.4.18 you will get a 401 error Unauthorized.
I just checked also in the svn trunk and it is the same as explained above: https://svn.freepascal.org/svn/projects/pas2js/trunk/packages/fcl-db/restconnection.pas

This solution was inspired by the code from the function TRESTDataProxy.DoGetData(...)

If you enable the log (through TSQLDBRestDispatcher.OnLog ) you will see the following message:
(User: ?) Resource: TEST1; Operation: PUT; Status: 401; Text: Unauthorized

Best regards
Simone Giacomelli

[code=pascal]

function TRESTDataProxy.ProcessUpdateBatch(aBatch: TRecordUpdateBatch): Boolean;
Var
  R : TRESTUpdateRequest;
  i : Integer;
  Method,URl : String;
begin
  Result:=False;
  For I:=0 to aBatch.List.Count-1 do
    begin
    R:=aBatch.List[i] as TRESTUpdateRequest;
    R.FBatch:=aBatch;
    R.FXHR:=TJSXMLHttpRequest.New;
    R.FXHR.AddEventListener('load', at R.onLoad);
    URL:=FConnection.GetRecordUpdateURL(R);
    Case R.Status of
      usInserted :
        Method:='POST';
      usModified:
        Method:='PUT';
      usDeleted:
        Method:='DELETE';
    end;
    R.FXHR.open(Method,URL);
    Connection.SetupRequest(R.FXHR); // <--------- I ADDED THIS LINE.
Without it you get a 401
    R.FXHR.setRequestHeader('content-type','application/json');
    if R.Status in [usInserted,usModified] then
      R.FXHR.Send(TJSJSON.Stringify(R.Data))
    else
      R.FXHR.Send;
    end;
  Result:=True;
end;

[/code]

Simone

Reply by email

Michael Van Canneyt
to Simone Giacomelli

Hi,

You are right, fixed in SVN, thank you !

Michael.

Simone Giacomelli wrote 64 lines
Dear coders, I think I found a fix for a problem (?) in the function below. The problem is that with the code in pas2js 1.4.18 you will get a 401 error Unauthorized. I just checked also in the svn trunk and it is the same as explained above: https://svn.freepascal.org/svn/projects/pas2js/trunk/packages/fcl-db/restconnection.pas This solution was inspired by the code from the function TRESTDataProxy.DoGetData(...) If you enable the log (through TSQLDBRestDispatcher.OnLog ) you will see the following message: (User: ?) Resource: TEST1; Operation: PUT; Status: 401; Text: Unauthorized Best regards Simone Giacomelli [code=pascal] function TRESTDataProxy.ProcessUpdateBatch(aBatch: TRecordUpdateBatch): Boolean; Var R : TRESTUpdateRequest; i : Integer; Method,URl : String; begin Result:=False; For I:=0 to aBatch.List.Count-1 do begin R:=aBatch.List[i] as TRESTUpdateRequest; R.FBatch:=aBatch; R.FXHR:=TJSXMLHttpRequest.New; R.FXHR.AddEventListener('load', at R.onLoad); URL:=FConnection.GetRecordUpdateURL(R); Case R.Status of usInserted : Method:='POST'; usModified: Method:='PUT'; usDeleted: Method:='DELETE'; end; R.FXHR.open(Method,URL); Connection.SetupRequest(R.FXHR); // <--------- I ADDED THIS LINE. Without it you get a 401 R.FXHR.setRequestHeader('content-type','application/json'); if R.Status in [usInserted,usModified] then R.FXHR.Send(TJSJSON.Stringify(R.Data)) else R.FXHR.Send; end; Result:=True; end; [/code] -- Simone _______________________________________________ Pas2js maillist - https://lists.freepascal.org/cgi-bin/mailman/listinfo/pas2js

Reply by email