I open a local html file using webview, and there is no problem using the file protocol. But for the sake of JavaScript, I have to use the http protocol, so I try to use old httpserver lib, but it cannot open html files. I am very confused about httperver and have little involvement in web apps. Can anyone help me see what the reason is? Thank you!
httpserver:
Private Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
Root.LoadLayout("MainPage")
server.Initialize("server")
server.Start(50551)
WebSet.setAllowFileAccess(WebView1,True)
Dim jo As JavaObject =WebView1
Dim settings As JavaObject = jo.RunMethod("getSettings", Null)
Dim r As Reflector
r.Target = settings
r.RunMethod2("setAllowUniversalAccessFromFileURLs", True, "java.lang.boolean")
End Sub
'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.
Private Sub Button1_Click
'It can open index.html with file protocol,but blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, isolated-app, chrome-extension, chrome, https, chrome-untrusted.
WebView1.LoadUrl($"${xui.FileUri(File.DirInternal & "/yux_storage/", "index.html")}"$)
'so I try to use httpserver to open local html file,but it can't open index.html.
WebView1.LoadUrl("http://127.0.0.1:50551" & File.DirInternal & "/yux_storage/index.html")
End Sub
Sub Server_HandleRequest (Request As ServletRequest, Response As ServletResponse)
'I think there should be something added here, but I don't know how to write it.
End Sub