如何使用基于TCP的HTTP下载图像?

编程入门 行业动态 更新时间:2024-10-28 16:26:16
本文介绍了如何使用基于TCP的HTTP下载图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我得到了一些图像使用HTTP下载。我得到了这些图片'URL,如何构建基于TCP的HTTP缓存下载图像?

I got some images to download using HTTP. I got these images' URL, how to build the TCP-based HTTP buffer to download the image?

我在我的当前平台没有图书馆,在这个平台上唯一支持的语言是C,所以我要建立对这些资源的HTTP缓存。

I got no library in my current platform, the only supported language in this platform is C, so I have to build the HTTP buffer for these resources.

目前我已经建立了正常的API请求,他们都是HTTP请求,每次请求有0个或多个参数。但图像请求只拿到了一个URL,如 HTTP://some-image.jpg ,这似乎只是一个下载工作,没有API的参数,没有授权,它的简单,但如何构建TCP请求?

Currently I have build the normal API request, they are all HTTP request, every request have 0 or more parameters. But the image request got only a URL, such as some-image.jpg, it seems just a download job, no API parameters, no authorization, it's simple, but how to construct the TCP request?

推荐答案

按照 HTTP: //www.jmarshall/easy/http/#sample ,我建立一个像我的TCP请求:

According to the www.jmarshall/easy/http/#sample, I build my TCP request like that:

sprintf(tcp_send_buf, "GET %s HTTP/1.1\r\nHost: %s\r\n\r\n", img_path, img_host); /* I wrapped TCP APIs for convenient, hope you understand it... */ set_host_and_port(img_host, 80); tcp_send(tcp_send_buf, strlen(tcp_send_buf), recv_callback);

在我的 recv_callback ,我得到了这样的服务器响应:

On my recv_callback, I got the server response like that:

HTTP/1.1 200 OK Content-Length: 42299 Content-Type: image/jpeg Last-Modified: Mon, 02 Jul 2007 07:58:47 GMT Accept-Ranges: bytes ETag: "e2c8b5d17ebcc71:15d5" Server: Microsoft-IIS/6.0 X-Powered-By: ASP.NET Date: Fri, 25 May 2012 01:33:57 GMT <binary image data>

我下载从Chrome中的图像,它的大小是一样的的Content-Length:42299 ,我觉得我得到的图像缓存

I downloaded the image from Chrome, and it's size is the same as Content-Length: 42299, I think I got the image buffer.

更多推荐

如何使用基于TCP的HTTP下载图像?

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

发布评论

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

>www.elefans.com

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