Click here to Skip to main content
15,890,123 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
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:

VB
 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)


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!
Posted
Updated 2-May-14 7:02am
v3
Comments
Sergey Alexandrovich Kryukov 2-May-14 13:49pm    
You tagged it as "HTML", but it is not just HTML. (VB.NET?) I guess you need to start your explanation with more general point of view.
Is it your own HTTP server, or what?
—SA
[no name] 2-May-14 15:36pm    
yes, it's a web server that i can access via public ip. i just need to know how to send the image using the img tag rather than getting its base64, which takes ages. you can go to 86.144.196.108:8080\DamonIsSlippy to view a single screenshot but it uses base64 hence the relatively long delay...
Sergey Alexandrovich Kryukov 2-May-14 16:41pm    
Very good, I think I got it.
—SA
[no name] 2-May-14 15:37pm    
and please don't DDoS :)
Sergey Alexandrovich Kryukov 2-May-14 16:38pm    
Excuse me, what is that supposed to mean?
—SA

1 solution

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
 
Share this answer
 
Comments
[no name] 3-May-14 9:07am    
But I don't know how to send things in the right way. It's hard to explain. All my application is doing is sending a html file to the browser but it's not sending images or the css file so it's plain text. I've used the VB code
response.ContentType = "text/html"
and then i'm sending the html contents but the css file is not working with the html, and no images are being sent either.
Sergey Alexandrovich Kryukov 3-May-14 19:55pm    
First of all, is it ASP.NET. If it is, what's unclear? You have all you need in HttpResponse class.
CSS? Did you embed it in HTML or not? If it is a separate file, it will be additional HTTP request/response.
Did you test your CSS with your HTML off-line first?
—SA
[no name] 4-May-14 10:17am    
the server was written in vb.net, the css is separate, and i tested it offline and it runs fine. i just don't know how to make/receive the second request.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900