Advertisement
Guest User

Untitled

a guest
Mar 30th, 2016
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.55 KB | None | 0 0
  1. // 1. Get the initial cookie.
  2. WinHttpClient getClient(L"http://www.codeproject.com/script/Membership/LogOn.aspx");
  3. 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");
  4. if (!getClient.SendHttpRequest())
  5. {
  6. return;
  7. }
  8.  
  9. // 2. Post data to get the authentication cookie.
  10. WinHttpClient postClient(L"http://www.codeproject.com/script/Membership/LogOn.aspx?rp=%2fscript%2fMembership%2fLogOn.aspx");
  11.  
  12. // Post data.
  13. // Change this to your Codeproject username and password.
  14. wstring username = L"YourCodeProjectUsername";
  15. wstring password = L"YourPassword";
  16. postClient.SetAdditionalRequestCookies(getClient.GetResponseCookies());
  17. string data = "FormName=MenuBarForm&Email=";
  18. data += (char *)_bstr_t(username.c_str());
  19. data += "&Password=";
  20. data += (char *)_bstr_t(password.c_str());
  21. data += "&RememberMeCheck=1";
  22. postClient.SetAdditionalDataToSend((BYTE *)data.c_str(), data.size());
  23.  
  24. // Post headers.
  25. 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";
  26. wchar_t szHeaders[MAX_PATH * 10] = L"";
  27. swprintf_s(szHeaders, MAX_PATH * 10, headers.c_str(), data.size());
  28. postClient.SetAdditionalRequestHeaders(szHeaders);
  29. if (!postClient.SendHttpRequest(L"POST", true))
  30. {
  31. return;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement