代码注释都写的很清楚,我们先利用rn分割得到每一行,其中第一行的数据是:
- GET /register.do?p={%22username%22:%20%2213917043329%22,%20%22nickname%22:%20%22balloon%22,%20%22password%22:%20%22123%22} HTTP/1.1
其中%22是双引号的url转码形式,%20是空格的url转码形式,然后我们根据空格分成三段,其中第二段就是我们的网址和参数:
- /register.do?p={%22username%22:%20%2213917043329%22,%20%22nickname%22:%20%22balloon%22,%20%22password%22:%20%22123%22}
然后我们根据网址与参数之间的问号将这个分成两段:第一段是网址,第二段是参数:
- 1bool HttpSession::Process(const std::shared_ptr<TcpConnection>& conn, const std::string& url, const std::string& param)
- 2{
- 3 if (url.empty())
- 4 return false;
- 5
- 6 if (url == "/register.do")
- 7 {
- 8 OnRegisterResponse(param, conn);
- 9 }
- 10 else if (url == "/login.do")
- 11 {
- 12 OnLoginResponse(param, conn);
- 13 }
- 14 else if (url == "/getfriendlist.do")
- 15 {
- 16
- 17 }
- 18 else if (url == "/getgroupmembers.do")
- 19 {
- 20
- 21 }
- 22 else
- 23 return false;
- 24
- 25
- 26 return true;
- 27}
然后我们根据url匹配网址,如果是注册请求,会走注册处理逻辑:
- void HttpSession::OnRegisterResponse(const std::string& data, const std::shared_ptr<TcpConnection>& conn)
- 2{
- 3 string retData;
- 4 string decodeData;
- 5 URLEncodeUtil::Decode(data, decodeData);
- 6 BussinessLogic::RegisterUser(decodeData, conn, false, retData);
- 7 if (!retData.empty())
- 8 {
- 9 std::string response;
- 10 URLEncodeUtil::Encode(retData, response);
- 11 MakeupResponse(retData, response);
- 12 conn->send(response);
- 13
- 14 LOG_INFO << "Response to client: cmd=msg_type_register" << ", data=" << retData << conn->peerAddress().toIpPort();;
- 15 }
- 16}
(编辑:晋中站长网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|