其中遇到了一个绕不过去的问题,即html页面中存在中文时,不能通过AHKHttp实现正确的加载。加载出来都是乱码。
主要代码如下,请各位大神帮忙看看如何解决,谢谢。
已尝试过这个地方的办法,问题还是存在。
https://blog.csdn.net/liuyukuan/article/details/53340917
HTML
Code: Select all
<html>
<head>
<meta charset='UTF-8'/>
<script>
function formSubmit()
{
var inpStr=document.getElementById("in_cmd").value;
// alert(inpStr);
var newUrl="http://127.0.0.1:8000/?channel="+ encodeURI(inpStr);
window.location.href=newUrl
document.getElementById("in_cmd").value=newUrl;
}
</script>
</head>
<title>HomePage-AHKhttp</title>
<body>
<b>Hello World</b><p>
<!-- <form action="/action_page.php"> -->
<form >
<label for="lname">Test Chinese:</label><br>
<input type="text" id="in_cmd" name="lname" width="300" height="128" value="我"><br><br>
<input type="button" value="Submit" onclick="formSubmit()">
</form>
</body>
</html>
Code: Select all
#Persistent
#SingleInstance, force
SetBatchLines, -1
FileRead, ahp, g.html
paths := {}
Loop, %A_WorkingDir%\*.png ;create a path for all png files in working dir
paths["/" . A_LoopFileName] := Func("ResourceLoader")
Loop, %A_WorkingDir%\*.mp4 ;create a path for all mp4 files in working dir
paths["/" . A_LoopFileName] := Func("ResourceLoader")
Loop, %A_WorkingDir%\*.css
paths["/" . A_LoopFileName] := Func("ResourceLoader")
Loop, %A_WorkingDir%\*.js
paths["/" . A_LoopFileName] := Func("ResourceLoader")
Loop, %A_WorkingDir%\*.jpg
paths["/" . A_LoopFileName] := Func("ResourceLoader")
Loop, %A_WorkingDir%\*.gif
paths["/" . A_LoopFileName] := Func("ResourceLoader")
for key, value in URLList
{
paths["/#" . key] := Func("OpenURL")
}
paths["/"] := Func("HelloWorld")
paths["404"] := Func("NotFound")
paths["/logo"] := Func("Logo")
server := new HttpServer()
server.LoadMimes(A_ScriptDir . "/mime.types")
server.SetPaths(paths)
server.Serve(8000)
return
Logo(ByRef req, ByRef res, ByRef server) {
server.ServeFile(res, A_ScriptDir . "/logo.ico")
res.status := 200
}
ResourceLoader(ByRef req, ByRef res, ByRef server) { ;every png has path registered to this function
server.ServeFile(res, A_WorkingDir . req.path)
res.status := 200
}
NotFound(ByRef req, ByRef res) {
res.SetBodyText("Page not found")
}
HelloWorld(ByRef req, ByRef res) {
global ahp
res.headers["Content-Type"] := "text/html; charset=utf-8"
chnl:=Uri.Decode(req.queries["channel"])
; msgbox %chnl%
res.SetBodyText(ahp)
res.status := 200
}
#include, %A_ScriptDir%\AHKhttp.ahk
#include %A_ScriptDir%\AHKSock.ahk