Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Community » Newbie corner » skylark with server and client
skylark with server and client [message #56048] Tue, 19 January 2021 05:25 Go to next message
BetoValle is currently offline  BetoValle
Messages: 203
Registered: September 2020
Location: Brasil Valinhos SP
Experienced Member
Hi,

in the application client i run the code (after server)


CONSOLE_APP_MAIN
{
      String url = "http://localhost:8001/myapp/qualqueres";   
      request.Post("id", "1234"); //** < --
      request.PostData("1111111");
      request.POST();
      String content = request.Execute(); 
       
      Cout() << "return " << content ;
  
      SetExitCode( 0 );
}


in the server application i run the code


SKYLARK(q, "qualqueres:POST")
{
   //**  "id" ??  "1234" ??  <--

   String c = http.GetRequestContent();

   http << c;
}

struct MyApp : SkylarkApp {
   MyApp() {
   root = "myapp";
  }
};

CONSOLE_APP_MAIN
{
   MyApp().Run();	
}



in the application client return the result "1111111".

my question:

in this adaptation I did how to make the parameter "id" and its value "1234"
passed by the client application, be read (evaluated) on the server and returned
to the client application?

(ie how do I read the parameters on the server, passed by the client, without manipulating
the traditional html?)

thanks





Re: skylark with server and client [message #56055 is a reply to message #56048] Tue, 19 January 2021 10:31 Go to previous messageGo to next message
Xemuth is currently offline  Xemuth
Messages: 387
Registered: August 2018
Location: France
Senior Member
Hello BetoBValle :

Request from client :
HttpRequest http("http://localhost:8001/serverSkylark/qualqueres");
//	http.POST().Header("id","1234"); //Via request header
//	http.POST().Post("id","1234"); //Via post Data
	http.POST().PostData("{\"id\":\"1234\"}"); //Via post data formated in JSON
	Cout() << http.Execute() << EOL;


Code to return 1234 from server :
SKYLARK(q, "qualqueres:POST")
{
   //String c = http.GetHeader("id"); //Via request header
   //String c =  http["id"]; //Via post data
   
   String c;
   String dataNotParsed = http.GetRequestContent(); //Via Post data formated in JSON
   Value json = ParseJSON(dataNotParsed);
   if(!IsNull(json["id"]))
		c = json["id"];
   
   http << c;
}

[Updated on: Tue, 19 January 2021 10:32]

Report message to a moderator

Re: skylark with server and client [message #56057 is a reply to message #56055] Tue, 19 January 2021 14:43 Go to previous messageGo to next message
BetoValle is currently offline  BetoValle
Messages: 203
Registered: September 2020
Location: Brasil Valinhos SP
Experienced Member

Hi,

in app client compiler show error line ...http.POST().Post("id","1234").. error: use of undeclared identifier 'http'

what are the contents of your client app includes?

thanks
Re: skylark with server and client [message #56058 is a reply to message #56057] Tue, 19 January 2021 15:05 Go to previous messageGo to next message
Xemuth is currently offline  Xemuth
Messages: 387
Registered: August 2018
Location: France
Senior Member
My 'http' is your 'request'.

#include <Core/Core.h>

using namespace Upp;

CONSOLE_APP_MAIN
{
	HttpRequest http("http://localhost:8001/serverSkylark/qualqueres");
//	http.POST().Header("id","1234"); //Via request header
//	http.POST().Post("id","1234"); //Via post Data
	http.POST().PostData("{\"id\":\"1234\"}"); //Via post data formated in JSON
	Cout() << http.Execute() << EOL;
}
Re: skylark with server and client [message #56062 is a reply to message #56057] Tue, 19 January 2021 16:37 Go to previous message
BetoValle is currently offline  BetoValle
Messages: 203
Registered: September 2020
Location: Brasil Valinhos SP
Experienced Member
sorry, after correcting the (my) HttpRequest and url (correct)
now work fine!


(1) param in post
   __ app Client
    #include <Core/Core.h>
    using namespace Upp;
    CONSOLE_APP_MAIN
    {
         HttpRequest http("http://localhost:8001/myapp/qualqueres");
         http.POST().Post("id","1234"); //Via post Data
         Cout() << http.Execute() << EOL;
    }
    __Server
    #include <Skylark/Skylark.h>
    using namespace Upp;
    SKYLARK(q, "qualqueres:POST")
    {
         String c =  http["id"]; //Via post data
         http << c;
    }
    struct MyApp : SkylarkApp {
    	MyApp() {
    		root = "myapp";
		
    	#ifdef _DEBUG
    		prefork = 0;
    		use_caching = false;
    	#endif
    	}
    };

    CONSOLE_APP_MAIN
    {
    #ifdef _DEBUG
    	StdLogSetup(LOG_FILE|LOG_COUT);
    	Ini::skylark_log = true;
    #endif
    	MyApp().Run();	
    }

(2)json 
     __app Client
    CONSOLE_APP_MAIN
    {
         HttpRequest http("http://localhost:8001/myapp/qualqueres");
         http.POST().PostData("{\"id\":\"1234\"}"); //Via post data formated in JSON
         Cout() << http.Execute() << EOL;
    }
    __Server
    SKYLARK(q, "qualqueres:POST")
    {
       String c;
       String dataNotParsed = http.GetRequestContent(); //Via Post data formated in JSON
       Value json = ParseJSON(dataNotParsed);
       if(!IsNull(json["id"]))
    		c = json["id"];
   
       http << c;
    }

(3) header
    __ app Client
    CONSOLE_APP_MAIN
    {
         HttpRequest http("http://localhost:8001/myapp/qualqueres");
     
         http.POST().Header("id","1234"); //Via request header
         Cout() << http.Execute() << EOL;
    }

    __  Server
    SKYLARK(q, "qualqueres:POST")
    {
       String c = http.GetHeader("id"); //Via request header
       http << c;
    }



Thanks!!!
Previous Topic: Skylark app - create pdf and donwload it
Next Topic: Cross Compiling?
Goto Forum:
  


Current Time: Sun Jun 16 18:31:32 CEST 2024

Total time taken to generate the page: 0.02246 seconds