-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.cpp
More file actions
67 lines (53 loc) · 1.89 KB
/
main.cpp
File metadata and controls
67 lines (53 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>
#include <string>
#include "../include/Server.h"
#include "../include/WebController.h"
#include "../include/JsonController.h"
#include "../include/JsonResponse.h"
using namespace std;
using namespace Mongoose;
class MyController : public WebController
{
public:
void hello(Request &request, StreamResponse &response)
{
// response << "Hello " << htmlEntities(request.get("username", "... what's your name ?")) << endl;
string username = request.get("username");
string passwd = request.get("passwd");
string body = response.getBody();
string data = request.getData();
cout << "username = " << username << endl;
cout << "passwd = " << passwd << endl;
cout << "request method = " << request.getMethod() << endl;
if (username == "yhj" && passwd == "123") {
response << "{\"msg\":\"Congratulations,Login success\"}" << endl;
} else {
response << "{\"msg\":\"Sorry,wrong username or password\"}" << endl;
}
response << "body = " << body << endl;
cout << "body = " << body << endl;
response << "data = " << data << endl;
cout << "data = " << data << endl;
/* string body = request.get("body","no body contaent");
cout << "body = " << body << endl;
response << body << endl;*/
}
void setup()
{
// addRoute("GET", "/hello", MyController, hello);
addRoute("POST","/hello",MyController,hello);
}
};
int main()
{
MyController myController;
Server server(8080);
server.registerController(&myController);
server.start();
cout << "Server has started,listening port is 8080 " << endl;
while (1) {
sleep(10);
}
}