|
|
Home » Community » Newbie corner » skylark with server and client
skylark with server and client [message #56048] |
Tue, 19 January 2021 05:25  |
BetoValle
Messages: 204 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   |
 |
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 #56062 is a reply to message #56057] |
Tue, 19 January 2021 16:37  |
BetoValle
Messages: 204 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!!!
|
|
|
Goto Forum:
Current Time: Mon Apr 28 13:33:33 CEST 2025
Total time taken to generate the page: 0.00704 seconds
|
|
|