lazarus Server for WebClientConnection1

From explorer i get json code and displayed correctly

When I try to read from WebClientConnection1, I have no answer

From http://code.jsontest.com/, WebClientConnection1 writes the answer

WebApplication:
procedure TForm1.WebButton2Click(Sender: TObject);
begin
WebMemo1.Lines.Clear;
if WebClientConnection1.Active then WebClientConnection1.Active := false;
WebClientConnection1.URI := WebEdit1.Text; // 'http://code.jsontest.com/';
WebClientConnection1.Active := true;
end;

procedure TForm1.WebClientConnection1DataReceived(Sender: TObject;
ARequest: TJSXMLHttpRequestRecord; var AResponse: string);
begin
WebMemo1.Lines.Clear;
WebMemo1.lines.Add(AResponse);
end;


Server:

program project1;
{$mode objfpc}{$H+}

uses
{$IFDEF UNIX}cthreads, cmem,{$ENDIF} sysutils, fphttpapp, httpdefs, httproute;

procedure timeEndpoint(req: TRequest; res: TResponse);

begin
res.Content := '{ "TMOV": [{ "codigo": "E", "descr": "Entrada" }, { "codigo": "S", "descr": "Salida" }'+
'], "SITS": [{"codigo": "1","descr": "Abierto"},{"codigo": "2", "descr": "En proceso"},{"codigo": "3",'+
'"descr": "Cerrado"}]}';

res.Code := 200;
res.ContentType := 'application/json';
res.CacheControl := 'private';
res.ContentLength := length(res.Content);
res.Date := DateToStr(now);

res.SendContent;

end;

begin
Application.Port := 8080;
HTTPRouter.RegisterRoute('/time', @timeEndpoint, true);
Application.Threaded := true;
Application.Initialize;
Application.Run;
end.

What is the browser console saying?

Whether this message is related to that:

[Exception... "Component returned failure code: 0x805e0006 [nsIChannel.asyncOpen]" nsresult: "0x805e0006 ()" location: "JS frame :: resource:///modules/FaviconLoader.jsm :: load :: line 174" data: no]
Content Security Policy: The page’s settings blocked the loading of a resource at

Where it can be fixed

whether WebClientConnection1 has the option to not control it

I'm not sure what header setting could be required here by the SQLDBBridge.
As mentioned, this is an open source server we did not write ourselves. The author(s) will be better positioned to answer the requirements for headers to use to make accesses.

can't use SQLDBBridge
does not work with a firebird that supports QuotedStr, for example
name table "Test"

I wrote a server that sends json but does not send favicon.ico

when I had a license for TMSFNCCloudPack I got HTTP Server Lazarus, but I don't have an example of how to use it

Now i'm trying to do it

It is important to me that one of the components of
WebClientconnection
WebSQLRestConnection
WebHttpRequest

read what i sent from the server to
procedure TForm1.WebClientConnection1DataReceived(Sender: TObject;
ARequest: TJSXMLHttpRequestRecord; var AResponse: string);
begin
WebMemo1.Lines.Clear;
WebMemo1.lines.Add(AResponse);
end;
....
as the explorer reads

I have no idea where the error

[Exception... "Component returned failure code: 0x805e0006 [nsIChannel.asyncOpen]" nsresult: "0x805e0006 ()" location: "JS frame :: resource:///modules/FaviconLoader.jsm :: load :: line 174" data: no]

comes from. I have no idea what FaviconLoader.jsm is. This looks all to be server related to code that you wrote.
If you are going to receive JSON, you might have to set the header for the request to:

Accept: application/json

you can check if you call
http://myserver.com/myendpoint
I set everything up and I need to get this answer
I will leave it temporarily

The problem is server side.

Test code:

procedure TForm1.WebButton1Click(Sender: TObject);
begin
  webhttprequest1.Headers.Clear;
  webhttprequest1.URL := 'http://myserver.com/myendpoint';
  webhttprequest1.Execute();
end;

procedure TForm1.WebHttpRequest1RequestResponse(Sender: TObject;
  ARequest: TJSXMLHttpRequestRecord; AResponse: string);
begin
  console.log(ARequest.req, AResponse);
end;

Errors in console:

Solve this by putting this JSON resource in the same domain as your web app or enable CORS on the backend. (This will depend on the type of backend you use).

For a background on CORS, please see:

For enabling CORS for XData this is explained in detail here:

Thanks Bruno,

enable CORS

'Access-Control-Allow-Origin: *'
'application/json'
component WebHttpRequest1 read json Error in console.

OR

'Access-Control-Allow-Origin: *'
'text/html'
component WebHttpRequest1 read json Not Error in console.

Can i ask you to delete the link which I set up

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