C语言抓http gzip包并解压 失败 - C/C++ - ChinaUnix.net -
2013-03-31 12:12
351 查看
C语言抓http gzip包并解压 失败 - C/C++ - ChinaUnix.net -
你的程序错误的地方目前看来还是比较多的。
while(1) {
i = read(sockfd,strResponse + templen,BUFSIZE-1);
}这个循环有可能在很长时间内都不会结束,如果你一定要这样循环,把请求头中的Connection: Keep-Alive改成Connection: close
而且每次用BUFSIZE-1有可能造成内存越界。
你用strstr查找CHUNKED时,要先把某个位置设为字符串结束位置,设为'\0'
事实上你不应该查找CHUNKED,你应该先对协议头的每一行查找Transfer-Encoding: ,然后再比较它的值是不是chunked,应该是用strncasecmp,大小写不分的。
综上,建议使用libcurl库。
你的程序错误的地方目前看来还是比较多的。
while(1) {
i = read(sockfd,strResponse + templen,BUFSIZE-1);
}这个循环有可能在很长时间内都不会结束,如果你一定要这样循环,把请求头中的Connection: Keep-Alive改成Connection: close
而且每次用BUFSIZE-1有可能造成内存越界。
你用strstr查找CHUNKED时,要先把某个位置设为字符串结束位置,设为'\0'
事实上你不应该查找CHUNKED,你应该先对协议头的每一行查找Transfer-Encoding: ,然后再比较它的值是不是chunked,应该是用strncasecmp,大小写不分的。
综上,建议使用libcurl库。
相关文章推荐
- C语言抓http gzip包并解压 失败 - C/C++ - ChinaUnix.net -
- 分享 C++命名空间的解释 http://blog.chinaunix.net/uid-26874138-id-3215266.html
- C语言 字符串处理函数 转自 http://blog.chinaunix.net/uid-25885064-id-3175049.html
- Iptables详解(文章来源于http://blog.chinaunix.net/uid-22780578-id-3346350.html)
- Linux下关于system调用 http://blog.chinaunix.net/uid-21768364-id-3995764.html
- 进程,轻量级进程,内核线程,用户线程的区别关系http://blog.chinaunix.net/xmlrpc.php?r=blog/article&uid=27025492&id=3441601
- 非阻塞connect 怎么判断连接成功? - C/C++ - ChinaUnix.net -
- ambari,hadoop本地源 部署http://blog.chinaunix.net/xmlrpc.php?r=blog/article&uid=26230811&id=4023821
- rand与srand函数的使用 http://blog.chinaunix.net/uid-25906157-id-3165140.html
- http://blog.chinaunix.net/uid-21501855-id-4490453.html
- Linux进程调度策略 http://blog.chinaunix.net/uid-20797562-id-99305.html
- http://bbs.chinaunix.net/thread-3573156-1-2.html
- 虚拟机安装linux 转自: http://blog.chinaunix.net/u1/35700/
- http://blog.chinaunix.net/uid-20569459-id-335214.html
- http://blog.chinaunix.net/uid-20322254-id-145835.html
- gentoo with gnome (来自 http://blog.chinaunix.net/uid-11009175-id-3549857.html)
- http://blog.chinaunix.net/uid-21222282-id-3244532.html
- socket TCP协议 http://blog.chinaunix.net/uid-22488454-id-3059636.html
- Linux 中open系统调用实现原理 2012-11-29 23:03:48 http://blog.chinaunix.net/uid-25968088-id-3426026.html