This commit is contained in:
lenheart
2025-04-21 13:36:35 +08:00
parent eeb773e723
commit 2ef9cfef42
87 changed files with 2134 additions and 765 deletions

View File

@@ -24,12 +24,12 @@ class Http {
return encoded;
}
function Request(Type, Url, Content) {
function Request(Type, Url, Content, DataType) {
local RequestBuffer = Type + " " + Url + " HTTP/1.1\r\nHost: " + Host + "\r\n";
if (Content) {
RequestBuffer += "Content-Length: " + Content.len() + "\r\n";
RequestBuffer += "Content-Type: application/x-www-form-urlencoded\r\n";
RequestBuffer += "Content-Type: " + DataType + "\r\n";
RequestBuffer += "\r\n";
RequestBuffer += Content;
} else {
@@ -39,16 +39,19 @@ class Http {
}
// 发送请求
function Post(Url, params = null) {
function Post(Url, params = null, DataType = "application/x-www-form-urlencoded") {
local content = null;
if (params != null && typeof params == "table") {
content = _EncodeParams(params); // 编码参数
}
return Request("POST", Url, content);
else if (params != null && typeof params == "string") {
content = params;
}
return Request("POST", Url, content, DataType);
}
function Get(Url, Content = null) {
return Request("GET", Url, Content);
function Get(Url, Content = null, DataType = "application/x-www-form-urlencoded") {
return Request("GET", Url, Content, DataType);
}
@@ -243,8 +246,7 @@ class HttpResponse {
response += "Content-Length: " + JsonString.len() + "\r\n";
response += "\r\n";
response += JsonString;
}
else if(typeof Msg == "string") {
} else if (typeof Msg == "string") {
response += "Content-Type: text/plain\r\n";
response += "Content-Length: " + Msg.len() + "\r\n";
response += "\r\n";