Gadgeteer.Networking, setting MIME type

Hi Everyone! My goal was that my first post would be an answer to a question instead of a question, but i guess i failed ^^

I’ve set up a simple working web server, using Gadgeteer.Networking, but MIME type is set to plain text, and my html is served as plain text. I can not figure out how to set the MIME type and i can not find any example code either… Help please? :slight_smile:

http://netmf.com/Gadgeteer/docs/GadgeteerCore/2.41.500/html/904eec17-9c5a-6e3f-f569-3e3d7607a136.htm

Have a nice Saturday :slight_smile:

Well, my first post didn’t turn out to be an answer, however, my second post will (at least partially) be an answer!

I converted the String webPage to a byte array and used another overloaded constructor to achieve what i wanted, and it worked on the first run. I still feel it’s not an optimal solution tho.

void webGui_WebEventReceived(string path, WebServer.HttpMethod method, Responder responder)
        {
            
            String webPage = "<!DOCTYPE html><meta charset=\"UTF-8\" /><html>\n";
            webPage += "<head><title>Sp(y)der Web Server</title></head>\n";
            webPage += "<body><table><tr>";
            webPage += "<td>" + "POPULATE" + "</td>" + "<td>" + "POPULATE" + "</td></tr>\n";

            webPage += "</table>\n";
            webPage += "</body>\n";
            webPage += "</html>\n";
            byte[] webPageToByte = StrToByteArray(webPage);
            responder.Respond(webPageToByte,"text/html");
                       
        }

Although I do not have an answer, I want to say welcome to the community :slight_smile:

Did you get any further with this? I’ve been running into the same limitation on the image side. How about a general purpose RLP that takes data in and spits out bytes formatted correctly back out? I imagine it would be quite a bit faster, especially when working with bitmaps like I am. I just can’t get around how slow it is to serve up a BMP when a JPEG or GIF would be so much smaller.

As for you specific issue, you can rework it to the following,

byte[] HTML = 
        Encoding.UTF8.GetBytes("<html><body><p>insert your text here".............

Add whatever you want and close with the following,

responder.Respond(HTML, "text/html"); 

and here is an example that would server an html file from the USB drive:


  using (FileStream fs = new FileStream(@ "\USB\index.htm", FileMode.Open, FileAccess.Read))
            {
                byte[] buf = new byte[fs.Length];
                fs.Read(buf, 0, buf.Length);
                responder.Respond(buf, "text/html");//set the MIME Type here
            }

Makes me want to start using JavaScript in addition to my HTML. Now I just need to figure out how to blend both byte streams (one for file system, and one from memory) to get that working… To be honest I might have better luck reading a Bitmap from the file system that has been encoded via JPEG than ever getting GT.Picture working.

So I ended up just sticking the JS on a sever and linking it in the script URL at the beginning of the response. It’s not self contained, but otherwise works really well. I’ve got HIGHcharts and RGraph running graphical output to my web page with only a few lines of HTML.