XDataWebDataSet Unauthorized

Hello I create server project with TXData and add JWT for authentication then i create web project by use TXDataWebConnection and TXDataWebDataSet. I can connect to server with my token by this code
XDataWebConnection.DesignData.Headers.AddPair('authorization', 'Bearer MyToken');
XDataWebConnection.Connected := True;
But when i load data from TXDataWebDataSet with XDataWebDataSet.Load i have error
"XData server request error. Uri: http://localhost:2001/tms/origin/tmeter_old Status code: 401 Unauthorized"
I can not find header property in TXDataWebDataSet please tell me what i do for this problem.
Sorry for my language.
Thank you.

DesignData is just a helper for you to connect at design-time. It should not be used at runtime. To set headers at runtime, please use OnRequest event as described here:


OnRequest event is called before every request about to be sent to the XData server. This is an useful event to modify all requests at once. For example, it's often used to add authentication information the request, like a authorization token with a JWT header:

procedure TForm1.XDataWebConnection1Request(Request: TXDataWebConnectionRequest);
  Request.Request.Headers.SetValue('Authorization', 'Bearer ' + LocalJWTToken);

It's work. Thank you very much for your help.

1 Like

This topic was automatically closed 60 minutes after the last reply. New replies are no longer allowed.