Notifications
Clear all
[Closed] Sending data to server with POST
Aug 02, 2018 6:27 am
I need to send The MACAddress to a server for licensing purposes.
I got the MACAddress using this Post.
I have tried to Convert a C# POST request to MaxScript but there are errors I can’t understand.
Req = (dotNetClass "System.Net.WebRequest").Create ("http://www.targetwebsite.com/targetlink");
Req.Method = "Post";
Req.ContentType = "Text/html";
Req.ContentLength = PostData.count;
Req.GetRequestStream().write PostData 0 PostData.count;
Res = Req.GetResponse();
1 Reply
Aug 02, 2018 6:27 am
Okay, I finally figured it out. here is the complete code for getting the mac address and sending it to a server with 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://www.targetwebsite.com/targetlink");
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());