Chcialbym sie jak zalogowac sie na stronie w c++(nie mam pomyslu jak to zrobic) programoje w dev
uint32_t Address = inet_addr(ipAddress);
if(Address == INADDR_NONE || Address == INADDR_ANY)
{
HE = gethostbyname(ipAddress);
if(HE != NULL)
Address = *((u_long*)HE->h_addr_list[0]);
}
SA.sin_addr.s_addr = Address;
#define URL "czepekpage.pl"
#define POST_URL "/index.php"
std::string login = "Czepek";
std::string password = "hasło";
char* sendBuffer = new char[255];
sprintf(sendBuffer, "POST %s HTTP/1.1\r\n"
"Connection: Keep-Alive\r\n"
"User-Agent: Mozilla Firefox/4.0\r\n"
"Content-Type: application/x-www-form-urlencoded\r\n"
"Accept-Charset: utf-8\r\n"
"Content-Length: %d\r\n"
"Host: %s\r\n\r\n", POST_URL, (login.size() + password.size() + strlen(POST_URL)), URL);
sprintf(sendBuffer, "page=data&account=%s&password=%s&send=go", login.c_str(), password.c_str());
if(con->sendTo(sendBuffer, strlen(sendBuffer) + 1))
int recvBytes = 0;
std::string fullRecvBuffer;
do
{
char recvBuffer[255];
recvBytes = recv(sock, recvBuffer, sizeof(recvBuffer), 0);
fullRecvBuffer += recvBuffer;
}while(recvBuffer > 0);
CURLcode res;
curl_global_init(CURL_GLOBAL_ALL);
struct curl_httppost* formPost = NULL;
struct curl_httppost* lastPtr = NULL;
struct curl_slist* headerList = NULL;
static const char buffer[] = "Expect:";
curl_formadd(&formPost, &lastPtr, CURLFORM_COPYNAME, "account", CURLFORM_COPYCONTENTS, account.c_str(), CURLFORM_END);
curl_formadd(&formPost, &lastPtr, CURLFORM_COPYNAME, "password", CURLFORM_COPYCONTENTS, password.c_str(), CURLFORM_END);
curl_formadd(&formPost, &lastPtr, CURLFORM_COPYNAME, "send", CURLFORM_COPYCONTENTS, "go", CURLFORM_END);
CURL* curl = curl_easy_init();
headerList = curl_slist_append(headerList, buffer);
if(curl)
{
curl_easy_setopt(curl, CURLOPT_URL, POST_URL);
curl_easy_setopt(curl, CURLOPT_HTTPPOST, formPost);
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
curl_formfree(formPost);
curl_slist_free_all(headerList);
}
CURLcode res;
curl_global_init(CURL_GLOBAL_ALL);
struct curl_httppost* formPost = NULL;
struct curl_httppost* lastPtr = NULL;
struct curl_slist* headerList = NULL;
static const char buffer[] = "Expect:";
curl_formadd(&formPost, &lastPtr, CURLFORM_COPYNAME, "account", CURLFORM_COPYCONTENTS, account.c_str(), CURLFORM_END);
curl_formadd(&formPost, &lastPtr, CURLFORM_COPYNAME, "password", CURLFORM_COPYCONTENTS, password.c_str(), CURLFORM_END);
curl_formadd(&formPost, &lastPtr, CURLFORM_COPYNAME, "send", CURLFORM_COPYCONTENTS, "go", CURLFORM_END);
CURL* curl = curl_easy_init();
headerList = curl_slist_append(headerList, buffer);
if(curl)
{
curl_easy_setopt(curl, CURLOPT_URL, POST_URL);
curl_easy_setopt(curl, CURLOPT_HTTPPOST, formPost);
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
curl_formfree(formPost);
curl_slist_free_all(headerList);
}