Home » Community » Newbie corner » skylark with server and client
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: Fri Jul 04 13:06:19 CEST 2025
Total time taken to generate the page: 0.04609 seconds
|