首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >CInternetSession::SetCookie示例

CInternetSession::SetCookie示例
EN

Stack Overflow用户
提问于 2014-10-10 07:27:28
回答 1查看 1.2K关注 0票数 0

CInternetSession::SetCookie的MSDN文档遵循InternetSetCookie Win32 message,但我不得不继续挖掘,以便在Managing Cookies under WinINet中找到一个示例。我认为使用它的示例代码是缺乏的,并且将是有用的。

EN

回答 1

Stack Overflow用户

发布于 2014-10-10 07:27:28

这就是我所拥有的:

代码语言:javascript
复制
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;

我的cookie-test.cgi看到my_cookie的值为"Set My Cookie!“

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26289580

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档