具有图像的Web服务器HTML响应 [英] Web server HTML response with image

查看:97
本文介绍了具有图像的Web服务器HTML响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



我有一个Web服务器,当有人通过Web浏览器向其发送请求时,它会返回一条消息。但我想制作一个复杂的html,需要一个图像。



我发送回复的代码是:



Hello,

I have a web server that returns a message when someone sends a request to it through a web browser. But I want to make a complex html, which needs an image.

My code to send the response is:

 Dim responseString As String = "<html>Welcome to my web server<img src = ""..."" alt = ""no image""></html>"
'So the html is <html>Welcome to my web server<img src = "..." alt = "no image"></html>
 Dim buffer() As Byte = System.Text.Encoding.UTF8.GetBytes(responseString)
 response.ContentLength64 = buffer.Length
 Dim output As System.IO.Stream = response.OutputStream
 output.Write(buffer, 0, buffer.Length)





但我不能获取要显示的图像。而是显示替代文本。

图像的绝对路径是C:\ Users \ Rixterz \Desktop\test\test\bin\debug \ image。 jpeg

这个应用程序的路径是C:\ Users\Rixterz \Desktop\test\test\bin\debug \ test.vshost

所以我以为img src =../ image.jpeg但替代文字不会消失!



请帮忙!



But I cannot get the image to display. Instead, the alt text is shown.
The absolute path to the image is C:\Users\Rixterz\Desktop\test\test\bin\debug\image.jpeg
This application's path is C:\Users\Rixterz\Desktop\test\test\bin\debug\test.vshost
So I thought the img src = "../image.jpeg" but the alt text won't go away!

Please help!

推荐答案

您需要使用HTTP响应发送适当的 content-type 。请参阅:

http://en.wikipedia.org/wiki/Content_type [< a href =http://en.wikipedia.org/wiki/Content_typetarget =_ blanktitle =New Window> ^ ]。



此处维护标准内容类型: http://www.iana.org/assignments /media-types/media-types.xhtml [ ^ ]。



图片类型在这里: http://www.iana.org/assignments/media-types/media-types.xhtml#image [ ^ ]。



-SA
You need to send appropriate content-type with the HTTP response. Please see:
http://en.wikipedia.org/wiki/Content_type[^].

The standard content types are maintained here: http://www.iana.org/assignments/media-types/media-types.xhtml[^].

Image types are here: http://www.iana.org/assignments/media-types/media-types.xhtml#image[^].

—SA


这篇关于具有图像的Web服务器HTML响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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