managed c++ - Logging into a forum with CURL (C++) -
i trying login website application in managed c++. i'm using curl this, , although i'm not receiving errors, i'm confused on how information needed check whether login successful or not. couldn't find similar issue mine unfortunately, appreciate help.
private: system::void blogin_click ( system::object^ sender, system::eventargs^ e ) { if ( system::string::isnullorempty ( tbusername->text ) ) { system::string^ str = gcnew system::string ( "login failed! please enter valid username." ); system::windows::forms::messagebox::show ( str ); return; } if ( system::string::isnullorempty ( tbusername->text ) ) { system::string^ str = gcnew system::string ( "login failed! please enter valid password" ); system::windows::forms::messagebox::show ( str ); return; } using system::runtime::interopservices::marshal; curl_global_init ( curl_global_all ); curl* curl = curl_easy_init (); if ( !curl ) { curl_global_cleanup (); return; } curl_easy_setopt ( curl, curlopt_ssl_verifypeer, 1l ); curl_easy_setopt ( curl, curlopt_ssl_verifyhost, 1l ); curl_easy_setopt ( curl, curlopt_useragent, "mozilla/4.0" ); curl_easy_setopt ( curl, curlopt_followlocation, 1 ); curl_easy_setopt ( curl, curlopt_url, "https://www.myurl.com/member.php?action=login" ); const char* szuser = static_cast< const char* >( marshal::stringtohglobalansi ( tbusername->text ).topointer () ); const char* szpass = static_cast< const char* >( marshal::stringtohglobalansi ( tbpassword->text ).topointer () ); curl_easy_setopt ( curl, curlopt_post, 1l ); curl_easy_setopt ( curl, curlopt_postfields, fmt::fmt ( "username=%s&password=%s", szuser, szpass ) ); //curl_easy_setopt ( curl, curlopt_userpwd, fmt::fmt ( "%s:%s", szuser, szpass ) ); std::string strdata; curl_easy_setopt ( curl, curlopt_writefunction, writecallback ); curl_easy_setopt ( curl, curlopt_writedata, &strdata ); curlcode res = curl_easy_perform ( curl ); /* curle_ok */ if ( res != curle_ok ) { system::windows::forms::messagebox::show ( "a error has occured during login process." ); } marshal::freehglobal ( system::intptr ( reinterpret_cast< long long >( szuser ) ) ); marshal::freehglobal ( system::intptr ( reinterpret_cast< long long >( szpass ) ) ); /* check if suceeded here... in strdata same whether credentials right or wrong */ curl_easy_cleanup ( curl ); curl_global_cleanup (); } also, website came "wildcard ssl" i'm not sure if matters? i'm pretty new of i'm sorry if i'm doing wrong.
distinguishing between successful login , failed 1 totally depends on reply offered server. don't know web application involved, can't provide more precise info.
secondly, using curl managed c++ project strange. have access .net framework provides http clients easier use, avoiding manual cleanup/marshaling.
Comments
Post a Comment