Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 1. Get the initial cookie.
- WinHttpClient getClient(L"http://www.codeproject.com/script/Membership/LogOn.aspx");
- getClient.SetAdditionalRequestHeaders(L"Accept: image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, application/x-ms-application, application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*\r\nAccept-Language: en-us\r\nUser-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; QQPinyin 730; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; InfoPath.2; CIBA; MS-RTC LM 8)\r\nAccept-Encoding: gzip, deflate\r\nProxy-Connection: Keep-Alive\r\nHost: www.codeproject.com\r\n");
- if (!getClient.SendHttpRequest())
- {
- return;
- }
- // 2. Post data to get the authentication cookie.
- WinHttpClient postClient(L"http://www.codeproject.com/script/Membership/LogOn.aspx?rp=%2fscript%2fMembership%2fLogOn.aspx");
- // Post data.
- // Change this to your Codeproject username and password.
- wstring username = L"YourCodeProjectUsername";
- wstring password = L"YourPassword";
- postClient.SetAdditionalRequestCookies(getClient.GetResponseCookies());
- string data = "FormName=MenuBarForm&Email=";
- data += (char *)_bstr_t(username.c_str());
- data += "&Password=";
- data += (char *)_bstr_t(password.c_str());
- data += "&RememberMeCheck=1";
- postClient.SetAdditionalDataToSend((BYTE *)data.c_str(), data.size());
- // Post headers.
- wstring headers = L"Accept: image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, application/x-ms-application, application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*\r\nReferer: http://www.codeproject.com/script/Membership/LogOn.aspx\r\nAccept-Language: en-us\r\nUser-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; QQPinyin 730; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; InfoPath.2; CIBA; MS-RTC LM 8)\r\nContent-Type: application/x-www-form-urlencoded\r\nHost: www.codeproject.com\r\nContent-Length: %d\r\nProxy-Connection: Keep-Alive\r\nPragma: no-cache\r\n";
- wchar_t szHeaders[MAX_PATH * 10] = L"";
- swprintf_s(szHeaders, MAX_PATH * 10, headers.c_str(), data.size());
- postClient.SetAdditionalRequestHeaders(szHeaders);
- if (!postClient.SendHttpRequest(L"POST", true))
- {
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement