正确的图像HTTP标头? [英] Correct HTTP Headers for Images?

查看:97
本文介绍了正确的图像HTTP标头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用C#编写一个Web服务器,只是为了它的乐趣,我能够将基本的文本文件提供给我的浏览器。但是,在提供图像时(例如, image.png ),我测试服务器的所有浏览器(IE,Firefox和Chrome)都显示某种占位符缩略图对于图像,好像图像已损坏或无效。

I'm writing a web server in C#, just for the fun of it, and I am able to serve basic text files to my browser. However, when serving up an image (say, image.png), all browsers that I test my server on (IE, Firefox, and Chrome) show some kind of placeholder thumbnail for the image, as if the image is corrupted or invalid.

我发送到浏览器的响应类似于

The response that I am sending to the browser looks like

HTTP/1.0 200 Ok
Content-Type: image/png
Content-Length: 14580053

{image data here}

我使用正确的HTTP标头吗?或者,如果我是,为什么浏览器不接受图像呢?

Am I using the correct HTTP headers? Or, if I am, why else would browsers not accept the image?

推荐答案

啊,想通了......我的代码忘了在响应正文之前添加额外的 \ n 。这根本不是标题的问题,只是错误的响应语法。

Ah, figured it out... my code forgot to add an extra \n before the response body. It wasn't a problem with the headers at all, just incorrect response syntax.

这篇关于正确的图像HTTP标头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆