首页 > 解决方案 > 使用 http POST 向服务器发送字符串

问题描述

我有一个 maxScript 需要将用户的 mac 地址发送到服务器并检查它是否包含在允许的列表中。
我必须部分获取mac地址并且服务器端已设置完毕。
唯一的问题是我希望它通过 POST 发送,这样会更安全,但我不知道该怎么做。

标签: http-postwebrequestmaxscript

解决方案


好吧,我终于想通了。以下是获取 mac 地址并使用 HttpPost 将其发送到服务器的完整代码:


    --Getting the mac address
        NI = dotnetclass "System.Net.NetworkInformation.NetworkInterface";
        NI.GetIsNetworkAvailable();
        ALL = NI.GetAllNetworkInterfaces();
        MACAddress = ALL[1].GetPhysicalAddress();
        print (MACAddress.toString());
    --Encoding the mac address so it is sendable
        A = (dotNetClass "System.Text.Encoding");
        PostData = "macaddress=" + MACAddress.toString();
        MData = A.ASCII.GetBytes (PostData);
    --Creating the Post request
        Req = (dotNetClass "System.Net.WebRequest").Create ("http://ip.mdfplan.com/");
        Req.Method = "Post";
        Req.ContentType = "application/x-www-form-urlencoded";
        Req.ContentLength = MData.count;
    --Writing the data in the request
        S = Req.GetRequestStream();
        S.write MData 0 MData.count;
        S.close();
    --Sending the request and recieving the response
        Res = Req.GetResponse();
        ResStr = Res.GetResponseStream();
    --Reading the respone
        objReader = dotnetobject "System.IO.StreamReader" ResStr;
        ResText = (objReader.ReadToEnd());

推荐阅读