sableangle/UnityHTTPServer

Runtime editing the 404 page

Closed this issue · 3 comments

stibuz commented

Hello, i'm using your simple script for making a webcontroller of my application on a AR Headset (Magic Leap2). I edit at edit-time the default 404 page so i obtain the desired page based on button names and other stuffs. What i'm asking is if there is a way to make those changes at runtime.. have i to stop and restart the server each time? Sorry for the probably stupid issue request, but i'm dealing now for my first time with json, http server from a c# perspective and with unity.
Thank you for any information!

Currently there is not method to override the 404 page in runtime.

But since the project is open source, I think you can have your modification base on your requirement, the part that handle the 404 content is here, modify the result as you wish.

byte[] resultByte = Encoding.UTF8.GetBytes(default404Page);

stibuz commented

Thank you very much for the fast answer! My problem is probably my bad understanding of the httplistener class, because 'ive tried to make the default404page no more constant but public, and accessing it from the outside in order to modify the myServer.default404Page works in edit mode (i update some names in the html string and they are showed correctly on runtime), the problem arises when trying to change it at runtime, i could try to use an external string insted of modifyng the internal one. Anyway very thank you for your simple but very useful work!

stibuz commented

Ok, i was doing a stupid mistake (not actually updating the 404page string in server instance). I can confirm that editing the default404Page or changing the page name in the suggested line makes the trick of changing it at runtime without the need of restarting the server.
I want only to confirm that it works in android (magic leap 2) if no html file is used, so i can confirm that NET is supported, while the datapath as to be adjusted for use in android due to apk compression of files.