int main ( int argc, char *argv[] ) { curl_global_init(CURL_GLOBAL_ALL); CHttpClient client = CHttpClient(); string strUrl = "http://192.168.1.249:80/TVAds/videocapture"; //strUrl = "http://app-test.kaipao.cc/v1/user/loginv"; string strInfo = "u=18814842159&p=111111&sign=42557FBC90E10CAD27FAC0F9D8BA94E9"; string strResp; cout << "POST ret: " << client.Post(strUrl, strInfo, strResp) << endl; cout << strInfo << endl << strResp <<endl; curl_global_cleanup(); return 0; } /* ---------- end of function main ---------- */
bool CController::InitLogin(tstring& strPhone, tstring& strPwd) { static int init_times(0); init_times++; //注册 todo if (NULL != m_pLogin) { delete m_pLogin; m_pLogin = NULL; } //verify ostringstream osPost; osPost<<"cell_phone=" <<strPhone.c_str() <<"&" <<"passwd=" <<strPwd.c_str(); tstring strUrl(WEB_SERVER_SITE_URL); strUrl += "verify"; tstring strPost = osPost.str().c_str(); tstring strResponse; CHttpClient reqClient; int nSucc = reqClient.Post(strUrl, strPost, strResponse); if (strResponse.empty()) { //只有在第一次连接的时候才会弹出对话框,以后为自动重连,不能弹出对话框 if (init_times <= 1) { CMsgBox* pMsgBox = new CMsgBox("错误",_T("连接服务器超时!"),MSGBOX_ICON_ERROR, MSGBOX_IDOK); pMsgBox->ShowModal(NULL); } return false; } //if (nSucc == 1) tstring strFind("access_token"); int index = strResponse.find(strFind); if (index == -1) { //解析错误码:"code":"1001"=密码错误,"code":"1003"="用户不存在" tstring strErrorPwd("\"code\":\"1001\""); tstring strErrorNotExist("\"code\":\"1003\""); int nIndex1 = strResponse.find(strErrorPwd); int nIndex2 = strResponse.find(strErrorNotExist); if (nIndex1 != -1) { CMsgBox* pMsgBox = new CMsgBox("错误",_T("密码错误!"),MSGBOX_ICON_ERROR, MSGBOX_IDOK); pMsgBox->ShowModal(NULL); } else if (nIndex2 != -1) { CMsgBox* pMsgBox = new CMsgBox("错误",_T("账户不存在!"),MSGBOX_ICON_ERROR, MSGBOX_IDOK); pMsgBox->ShowModal(NULL); } else { CMsgBox* pMsgBox = new CMsgBox("错误",_T("用户验证失败!"),MSGBOX_ICON_ERROR, MSGBOX_IDOK); pMsgBox->ShowModal(NULL); } return false; } index += strFind.length()+3; if (!strResponse.empty()) { tstring strToken = strResponse.substr(index, 32/*strResponse.length()-index-2*/); //计算token长度 if (!strToken.empty()) { m_strToken = strToken; m_pLogin = new CLogin(strPhone, strPwd); if (NULL != m_pLogin) { return m_pLogin->LoginToServer(); } } } return false; }