如题:
测试的web服务器端代码如下:
sprintf_s(customhtml2, sizeof(customhtml2), "HTTP/1.1 200 OK\r\n set-Cookie:sid=%u;path=/ ", u_session_id);
string strhtml1 = string(customhtml2);
strhtml1 += "\r\n\r\n";
ifstream infile("loginSuc.html", ios::in | ios::_Nocreate);
if (!infile){
cout << "open loginSuc.html fail,the error code:" << GetLastError() << endl;
continue;
}
infile.read(CustomHtml, sizeof(CustomHtml));
if (strlen(CustomHtml) <= 0){
cout << "read loginSuc.html fail" << endl;
continue;
}
string strhtml2 = string(CustomHtml);
strhtml1 += strhtml2;
strcpy_s(CustomHtml,strhtml1.c_str());
int sendNum = send(socketArray[p].s_socket, CustomHtml, strlen(CustomHtml), 0);
cout << CustomHtml;
就是将响应头和响应体拼起来发回客户端
获取的响应如下图:
但是当客户端继续访问其他页面时候,请求头里面并没有cookie这个首部。是怎么回事?????熟悉的大神求助
C++web服务器响应头设置set-cookie无效
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
2条回答 默认 最新
- pangxinna 2015-10-22 09:07关注
自己找到答案了,之前忘了在哪看的 有<>,坑死我了,把<>拿掉。直接写 HTTP/1.1 200 OK\r\n set-Cookie:sid=%u;path=/ 就可以了,客户端之后再请求的时候自动就带cookie了。纠结很久的问题总算解决了。。。。。
解决 无用评论 打赏 举报
悬赏问题
- ¥15 程序不包含适用于入口点的静态Main方法
- ¥15 素材场景中光线烘焙后灯光失效
- ¥15 请教一下各位,为什么我这个没有实现模拟点击
- ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
- ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
- ¥20 有关区间dp的问题求解
- ¥15 多电路系统共用电源的串扰问题
- ¥15 slam rangenet++配置
- ¥15 有没有研究水声通信方面的帮我改俩matlab代码
- ¥15 ubuntu子系统密码忘记