http-post - 使用 http POST 向服务器发送字符串
问题描述
我有一个 maxScript 需要将用户的 mac 地址发送到服务器并检查它是否包含在允许的列表中。
我必须部分获取mac地址并且服务器端已设置完毕。
唯一的问题是我希望它通过 POST 发送,这样会更安全,但我不知道该怎么做。
解决方案
好吧,我终于想通了。以下是获取 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());
推荐阅读
- ios - 如何动态设置自定义 UIView 类的高度,并将 XIB 添加到垂直堆栈视图?
- r - 多个变量的夏皮罗测试错误:
- javascript - 如何从子组件 onClick 访问和 setState() 的父组件
- python - 无法比较日期变量和熊猫数据框之间的日期
- c++ - 如何使用 C++ 显示连接到网络的设备的名称和 IP 地址
- angular - ngIf 可以在 Angular 1.5 中引用嵌套 ngFor 中的变量。如何在 Angular 10 中实现同样的效果?
- node.js - 在 GCP 环境之外进行 POST 调用以创建工作负载身份
- scala - 如何使用 spark scala 将整数转换为 Varchar(8)
- javascript - ReactJS如何在刷新页面时保持状态值
- javascript - VueJS 仅在一个选项卡上执行后台操作