0
CInternetSession :: SetCookie的MSDN文檔取決於InternetSetCookie Win32 message,但我不得不繼續挖掘以找到Managing Cookies under WinINet中的示例。我認爲使用它的示例代碼是缺乏的,並且會有用。CInternetSession :: SetCookie示例
CInternetSession :: SetCookie的MSDN文檔取決於InternetSetCookie Win32 message,但我不得不繼續挖掘以找到Managing Cookies under WinINet中的示例。我認爲使用它的示例代碼是缺乏的,並且會有用。CInternetSession :: SetCookie示例
這裏是我:「我的設置曲奇」
CInternetSession session;
CHttpConnection* connection=0;
try {
INTERNET_PORT port = 80;
CString server("mydomain.com");
CString path("/cookie-test.cgi");
CString cookieUrl("http://"+server+path);
BOOL res = session.SetCookie((LPCSTR)cookieUrl,0,"my_cookie=Set My Cookie!");
if(res == FALSE) {
DWORD error GetLastError();
// code to format error message
}
connection = session.GetHttpConnection(server,port);
file = connection->OpenRequest(
CHttpConnection::HTTP_VERB_GET, //Action verb
path //Object to perform action on
,0,1,0,0,INTERNET_FLAG_*); // pick your flags
file->SendRequest();
// Check status, read response, process
}
catch(CInternetException *e) {
// report error
}
connection->Close();
file->Close();
delete file;
delete connection;
我的餅乾test.cgi看到my_cookie具有的價值