/*
文件名:HttpClass.nut
路径:Dps_A/BaseClass/HttpClass/HttpClass.nut
创建日期:2024-10-16	18:41
文件用途:Http类
*/
class Http {

    Host = null;
    Service = null;

    constructor(host, service = "http") {
        Host = host;
        Service = service;
    }

    function Request(Type, Url, Content) {
        local Request = Type + " " + Url + " HTTP/1.1\r\nHost: " + Host + "\r\n";

        if (Content) {
            Request += "Content-Length: " + Content.len() + "\r\n";
            Request += "Content-Type: application/x-www-form-urlencoded\r\n";
            Request += "\r\n";
            Request += Content;
        } else {
            Request += "Connection: close\r\n\r\n";
        }
        return Sq_CreateHttp(Host, Service, Request);
    }

    // 发送请求
    function Post(Url, Content = null) {
        return Request("POST", Url, Content);
    }

    function Get(Url, Content = null) {
        return Request("GET", Url, Content);
    }
}

Timer.SetTimeOut(function() {
    // local Dio = Http("192.168.200.189", "45123");
    // local Jso = {
    //     a = 1,
    //     b = 4.8,
    //     c = "测试"
    // }
    // local JsonStr = Json.Encode(Jso);
    // local Res = Dio.Post("/", JsonStr);
    // print(Res);

    // local NowTimesstamp = Sq_GetTimestampString();
    // print(NowTimesstamp);

    // local Trad = Sq_Conversion("這是繁體語句", 0);
    // local Simple = Sq_Conversion("这是简体语句", 1);
    // print(Trad);
    // print(Simple);
    
}, 0);

// local Dio = Http("myip.ipip.net", "443");
// local Res = Dio.Get("/", "");

// print(Res);