我做一个客户端与http服务器连接,记录它的网页内容

newman0708 2005-01-14 10:45:51
我做一个客户端与http服务器连接,记录它的网页内容。

我先是与服务器连接(连上了),
我向服务器发请求信息,
cs->receive(Buffer,READCOUNT);//就停在这里,什么都收不到,

是我的请求信息不对吗?


GET /{0} HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg,application/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword, */*
Accept-Language: zh-cn
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; MyIE2; .NET CLR 1.1.4322)
Host: {1}
Connection: Keep-Alive
{0} index{2}.htm
{1} 10.126.9.139
{2}rang 1 6


for(int i=rangeS;i<=rangeE;i++){
CppSocket cs(host,80);
cs.connect();
string msgFull,temp;
temp=msg_vector[pos];
ostrstream os;
os<<i;
msgFull=msg_vector[pos].replace(msg_vector[pos].find_first_of("{2}"),3,os.str(),0,os.pcount());
delete os.str();
for(int j=0;j<msg_vector.size();j++){
cs.send(msg_vector[j],msg_vector[j].length());
msg=msg_vector[j];
}
cs.send("\n\n",2);

msg_vector[pos]=temp;
parseRecv(i,&cs);
cs.close();
}

bool parseRecv(int num,CppSocket* cs){
char Buffer[READCOUNT];
::ZeroMemory(Buffer,READCOUNT);

cs->receive(Buffer,READCOUNT);//就停在这里,什么都收不到
string str(Buffer),str1;

int pos,pos2,ch;
str1=str;
for(int i=0;i<str1.length();i++){
ch=(int )str1[i];
if((ch>64)&&(ch<91))
str1[i]=tolower(str1[i]);
}
pos=str1.find("<title>",0);
......
}

...全文
100 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
robothn 2005-01-17
  • 打赏
  • 举报
回复
cs.send("\n\n",2);

应该是发送 cs.send("\r\n\r\n",4);

64,646

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧