#1 2013-06-18 03:44:38

Luzcka
Member
From: Brazil / Chile
Registered: 2012-12-07
Posts: 20

Call methods from browser / GetHttp

Hi!
I changed the demo 16 (Execute SQL via services) to work with Zeos-Firebird, worked fine
with the client program's own demo. But I would like to access methods via browser as shown
below where access DataSnap server using Synapse.

if HttpGetText ('http://127.0.0.1:8888/datasnap/rest/TLogMethods/Register/Mi Test', vResponse) then (...)

The idea is to be able to access the methods using any language without thinking for now in security...
I tried using the following URL: http://localhost:8080/root/RemoteSQL {"method": "Connect", "params": ['localhost', '. \Data\DB-UTF8.FDB', 'sysdba' , 'masterkey'], "id": 0}

Adding the following line: aServer.ServicesRouting: = rmJSON_RPC

The complete code would be:

const
   cntDatabaseFile = 'ECONSULTOR UTF8.FDB-';
var
   Amodel: TSQLModel;
   aServer: TSQLRestServer;
   aHTTPServer: TSQLHttpServer;
begin
   TSQLLog.Family begin with the
     Level: = LOG_VERBOSE;
     EchoToConsole: = LOG_VERBOSE;
   end;
   AllocConsole;
   TextColor (ccLightGray);
   Amodel: TSQLModel.Create = ([], ROOT_NAME);
   try
     aServer: = TSQLRestServerFullMemory.Create (Amodel, 'users.json', false, false) // Era true en la autenticacion
     try
       
       aServer.ServicesRouting: = rmJSON_RPC;
      
       aHTTPServer: = TSQLHttpServer.Create ('8080 '[aServer] "+", useHttpApiRegisteringURI);
       try
         aHTTPServer.AccessControlAllowOrigin: = '*';
         writeln (# 10'Background server is running. '# 10);
         writeln ('Press [Enter] to close the server.' # 10);
         ConsoleWaitForEnterKey;
       finally
         aHTTPServer.Free;
       end;
     finally
       aServer.Free;
     end;
   finally
     aModel.Free;
   end;
end.

But the response is:

{
"ErrorCode": 400,
"ErrorText": "Bad Request"
}

Without the line "aServer.ServicesRouting: = rmJSON_RPC;" and using the URL
http://localhost:8080/root/RemoteSQL.Connect  (intentionally without parameters)
the response is:

{
"ErrorCode":400,
"ErrorText":"Parameters required"
}

but the parameter formats I tried did not work...

What is the correct format?? What is the best format thinking of something simple that can be easily mounted??
For the case of wanting to use the parameters in this way is best to use interface-based services or Methods-based services??
Is it possible to register more services using "aServer.ServiceRegister (...)" in order to separate the classes and their methods using the same server??

Offline

#2 2013-06-18 05:09:28

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,182
Website

Re: Call methods from browser / GetHttp

As stated by the SAD pdf documentation, the expected method is POST, not GET, in your case.

The easiest is to run the server in the IDE debugger, and find out what is not as expected.

Method-based services are probably easier to work with, if your purpose is to tune the exchange format. But there is more work to do on the server side to marshall the parameters.

And, of course, you can register several services, as stated by the documentation and the regression tests!
(the TestSQL3.dpr regression tests are very informative, in fact)

Offline

#3 2013-09-11 15:17:21

corchi72
Member
Registered: 2010-12-10
Posts: 232

Re: Call methods from browser / GetHttp

sorry but in the end, what is the correct string that I must to put in the browser to run a simple query?

Example
http://localhost:8080/root/RemoteSQL.Execute And then what should I write to execute a select * from customer  where id = 1

I use the example "16 - Execute SQL via services" to read data from an external source and interrogate them via http from an Internet browser.


Thanks corchi

Offline

#4 2013-09-11 15:39:33

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,182
Website

Re: Call methods from browser / GetHttp

Use the debugger on the client side to get the exact uri and method. And check the sent json body, depending on the routing scheme.

Offline

#5 2013-09-11 16:17:15

corchi72
Member
Registered: 2010-12-10
Posts: 232

Re: Call methods from browser / GetHttp

in which unit and which method should I enter my breakpoint.Io I had already tried to debug but did not succeed.

which is the variable to be read?

thanks corchi72

Offline

Board footer

Powered by FluxBB