fix token header name

This commit is contained in:
chatlanin 2024-07-12 12:01:41 +03:00
parent c9c47c1297
commit 4b534505c2
2 changed files with 9 additions and 6 deletions

View File

@ -78,7 +78,7 @@ namespace trs
{ {
res.set_header("Access-Control-Allow-Origin", "*"); res.set_header("Access-Control-Allow-Origin", "*");
res.set_header("Allow", "POST, HEAD, OPTIONS"); res.set_header("Allow", "POST, HEAD, OPTIONS");
res.set_header("Access-Control-Allow-Headers", "X-Requested-With, Content-Type, Accept, Origin, Authorization, TRS-server-function, TRS-token-auth"); res.set_header("Access-Control-Allow-Headers", "X-Requested-With, Content-Type, Accept, Origin, Authorization, TRS-server-function, TRS-server-token");
res.set_header("Access-Control-Allow-Methods", "OPTIONS, HEAD, POST"); res.set_header("Access-Control-Allow-Methods", "OPTIONS, HEAD, POST");
}); });
} }
@ -120,13 +120,16 @@ namespace trs
~client() = default; ~client() = default;
public: public:
auto notify(std::string path, std::string key, std::string data) auto post(std::string path, JSON&& data)
{ {
httplib::Headers headers = { httplib::Headers headers = {
{ "TRS-token-auth", m_token }, { "TRS-server-token", m_token },
{ "TRS-server-function", "notify" } { "TRS-server-function", "notify" },
{ "Content-Type", "application/json" },
{ "Cookie", "unione_lang=ru" }
}; };
return m_cli.Post(path, headers, httplib::Params{{key, data}});
return m_cli.Post(path.c_str(), headers, data.dump(),"application/json" );
} }
private: private:

View File

@ -27,7 +27,7 @@ namespace worckspaces
auto main(int argc, char* args[]) -> int auto main(int argc, char* args[]) -> int
{ {
trs::client cli {"localhost:5000", "token_auth"}; trs::client cli {"localhost:5000", "token_auth"};
cli.notify("/","test", "test message"); cli.post("/",trs::JSON{{ "test", "test message" }});
// trs::server srv; // trs::server srv;
// srv.init("test service", "app_connection", "log_connection"); // srv.init("test service", "app_connection", "log_connection");