使用Socket请求Http连接的问题。
调用下面这个方法请求iis服务器返回页面信息 request = "GET /atm/application/Login.aspx HTTP/1.1\r\n" + "Host: atm\r\n" + "Connection: Keep_Alive\r\n" + "Cookie: ATMuserId=6000000816\r\n\r\n";
只有当request中的Connection段为Close时才能返回应答信息,而Keep_Alive时无法返回应答信息,我的程序需要Keep_Alive,请问如何获得服务端的应答信息。
private static string SocketSendReceive(Socket socket, string request)
{
if (socket == null) throw new ArgumentNullException("socket", "Socket对象不可为空!");
if (string.IsNullOrEmpty(request)) throw new ArgumentNullException("request","请求消息不可为空!");
Socket s = socket;
string msg = request;
Byte[] buffOfSent = Encoding.ASCII.GetBytes(msg);
Byte[] buffOfReceived = new Byte[1024]; // 返回的消息缓冲。
string retMsg = string.Empty; // 返回的消息。
int count = 0; // 服务器回发内容计数。
// 发送请求。
s.Send(buffOfSent, buffOfSent.Length, 0);
s.BeginReceive(
// 该阻塞直到数据传输完成。
do
{
count = s.Receive(buffOfReceived, buffOfReceived.Length, 0);
retMsg = retMsg + Encoding.ASCII.GetString(buffOfReceived, 0, count);
}
while (count > 0);
return retMsg;
}
只有当request中的Connection段为Close时才能返回应答信息,而Keep_Alive时无法返回应答信息,我的程序需要Keep_Alive,请问如何获得服务端的应答信息。
private static string SocketSendReceive(Socket socket, string request)
{
if (socket == null) throw new ArgumentNullException("socket", "Socket对象不可为空!");
if (string.IsNullOrEmpty(request)) throw new ArgumentNullException("request","请求消息不可为空!");
Socket s = socket;
string msg = request;
Byte[] buffOfSent = Encoding.ASCII.GetBytes(msg);
Byte[] buffOfReceived = new Byte[1024]; // 返回的消息缓冲。
string retMsg = string.Empty; // 返回的消息。
int count = 0; // 服务器回发内容计数。
// 发送请求。
s.Send(buffOfSent, buffOfSent.Length, 0);
s.BeginReceive(
// 该阻塞直到数据传输完成。
do
{
count = s.Receive(buffOfReceived, buffOfReceived.Length, 0);
retMsg = retMsg + Encoding.ASCII.GetString(buffOfReceived, 0, count);
}
while (count > 0);
return retMsg;
}
...全文
相关推荐
基于Python+flask+mongodb WEB开发的个人知识管理系统详细文档+资料齐全.zip
【资源说明】 基于Python+flask+mongodb WEB开发的个人知识管理系统详细文档+资料齐全.zip 【备注】 1、该项目是个人高分项目源码,已获导师指导认可通过,答辩评审分达到95分 2、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用! 3、本项目适合计算机相关专业(人工智能、通信工程、自动化、电子信息、物联网等)的在校学生、老师或者企业员工下载使用,也可作为毕业设计、课程设计、作业、项目初期立项演示等,当然也适合小白学习进阶。 4、如果基础还行,可以在此代码基础上进行修改,以实现其他功能,也可直接用于毕设、课设、作业等。 欢迎下载,沟通交流,互相学习,共同进步!
Python Flask +MongoDB个人文件管理系统后台.zip
Python Flask +MongoDB个人文件管理系统后台.zip
kispower是一个集成了:时间管理、知识管理、网址导航、博客相册,基于WEB的个人知识管理系统。用python+flask+mongodb开发.zip
kispower是一个集成了:时间管理、知识管理、网址导航、博客相册,基于WEB的个人知识管理系统。用python+flask+mongodb开发.zip
flask+mongodb 物联网后台管理系统.zip
flask+mongodb 物联网后台管理系统.zip
大三上学期,python课程设计,课堂管理系统,采用flask,mongodb,react,mpvue.zip
大三上学期,python课程设计,课堂管理系统,采用flask,mongodb,react,mpvue.zip


