如何获取HTML页面使用套接字

编程入门 行业动态 更新时间:2024-10-26 05:34:43
本文介绍了如何获取HTML页面使用套接字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

大家好 我使用套接字获取html页面 和请求标签"Accept-Encoding:gzip",因此我收到了压缩数据 我尝试使用zlib解压缩,但是调用函数inflate 时失败 我使用以下代码:

hi all i use socket to fetch the html page and the request tag "Accept-Encoding:gzip" so i recieve a compress data i try use zlib to uncompress but i failed when i call function inflate i use the code follow:

#define CHUNK 16384 int inflate_read(char *source,int len,char **dest,int gzip) { int ret; unsigned have; z_stream strm; unsigned char out[CHUNK] = {0}; int totalsize = 0; /* allocate inflate state */ strm.zalloc = Z_NULL; strm.zfree = Z_NULL; strm.opaque = Z_NULL; strm.avail_in = 0; strm.next_in = Z_NULL; if(gzip) ret = inflateInit2(&strm, 47); else ret = inflateInit(&strm); if (ret != Z_OK) return ret; strm.avail_in = len; strm.next_in = (Bytef*)source; /* run inflate() on input until output buffer not full */ do { strm.avail_out = CHUNK; strm.next_out = out; ret = inflate(&strm, Z_NO_FLUSH); assert(ret != Z_STREAM_ERROR); /* state not clobbered */ switch (ret) { case Z_NEED_DICT: ret = Z_DATA_ERROR; /* and fall through */ case Z_DATA_ERROR: case Z_MEM_ERROR: inflateEnd(&strm); return ret; } have = CHUNK - strm.avail_out; totalsize += have; *dest = (char*)realloc(*dest,totalsize); memcpy(*dest + totalsize - have,out,have); } while (strm.avail_out == 0); /* clean up and return */ (void)inflateEnd(&strm); return ret == Z_STREAM_END ? Z_OK : Z_DATA_ERROR; }

有人可以帮我解压缩数据,并使用"Transfer-Encoding:chunked"解压缩数据 谢谢

someone can help me how to uncompress data and uncompress data with "Transfer-Encoding: chunked" thank you

推荐答案

此代码获取html页面.将html页面的地址而不是example提取.下面发布的代码来自 curl.haxx.se/libcurl/c/simple.html [^ ] This code gets html page. Put html page''s address to fetch instead of example. Below posted code is from curl.haxx.se/libcurl/c/simple.html[^] #include <stdio.h> #include int main(void) { CURL *curl; CURLcode res; curl = curl_easy_init(); if(curl) { curl_easy_setopt(curl, CURLOPT_URL, "example"); res = curl_easy_perform(curl); /* always cleanup */ curl_easy_cleanup(curl); } return 0; } Y</stdio.h>

更多推荐

如何获取HTML页面使用套接字

本文发布于:2023-08-07 03:47:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1316797.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:页面   HTML

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!