免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 6656 | 回复: 5
打印 上一主题 下一主题

用http协议下载图片的问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-02-19 17:51 |只看该作者 |倒序浏览
5可用积分
自己写的一个用http协议下载文件的小程序,但是,
当下载jpeg格式的图片的时候,有时候(并非所有)下载的图片
无法显示,而用wget下载却可以显示,比较了一下,
发现自己的代码下载的图片与wget下载的图片文件大小不一样。

请问,这是为什么啊?
用http协议下载的东西是不是有的还需要进行格式转换啊?

最佳答案

查看完整内容

1.去掉 HTTP 协议头2.Chunck编码

论坛徽章:
5
2015年辞旧岁徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:53:172015亚冠之水原三星
日期:2015-06-02 16:34:202015年亚冠纪念徽章
日期:2015-10-19 18:13:37程序设计版块每日发帖之星
日期:2015-11-08 06:20:00
2 [报告]
发表于 2009-02-19 17:52 |只看该作者
1.去掉 HTTP 协议头
2.Chunck编码

论坛徽章:
1
2015年辞旧岁徽章
日期:2015-03-03 16:54:15
3 [报告]
发表于 2009-02-19 17:53 |只看该作者
fopen( ....., "wb" );

另外该用 memcpy 就不要用 strlen。

论坛徽章:
0
4 [报告]
发表于 2009-02-19 18:35 |只看该作者
19.4.6 Introduction of Transfer-Encoding

HTTP/1.1 introduces the Transfer-Encoding header field (section 14.41). Proxies/gateways MUST remove any transfer-coding prior to forwarding a message via a MIME-compliant protocol.

A process for decoding the "chunked" transfer-coding (section 3.6) can be represented in pseudo-code as:

       length := 0
       read chunk-size, chunk-extension (if any) and CRLF
       while (chunk-size > 0) {
          read chunk-data and CRLF
          append chunk-data to entity-body
          length := length + chunk-size
          read chunk-size and CRLF
       }
       read entity-header
       while (entity-header not empty) {
          append entity-header to existing header fields
          read entity-header
       }
       Content-Length := length
       Remove "chunked" from Transfer-Encoding
谢谢了。

论坛徽章:
0
5 [报告]
发表于 2009-02-19 19:12 |只看该作者
gzip
ps,用libcurl

论坛徽章:
0
6 [报告]
发表于 2009-02-19 22:31 |只看该作者
为什么不用wget.
精髓不是写模块,而是你写的程序就能当通用的命令用,而你又可以利用已经有的命令实现功能.
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP