[Pas2js] Pas2js issue in posting a modified record - TRESTDataProxy

Michael Van Canneyt michael at freepascal.org
Sun Feb 23 20:37:06 CET 2020


Hi,

You are right, fixed in SVN, thank you !

Michael.

On Sun, 23 Feb 2020, Simone Giacomelli wrote:

> 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  -  Pas2js at lists.freepascal.org
> https://lists.freepascal.org/cgi-bin/mailman/listinfo/pas2js


More information about the Pas2js mailing list