Notifications
Clear all

[Closed] webrequest with POST max 2016

Has anyone encountered problems with sending information via “POST” using webrequest in max 2016?

At me everything works great in max 2012 and max 2014 but not in 2016.

6 Replies

Seems to work fine here with HttpWebRequest. Can you post an example of what’s not working for you?

of course, here it is:

(
 	local htmlString =""
 	fn Completed sender arg =
 		(
 			print "completed"
 			sender.Dispose();
 			if (htmlString !=undefined) and htmlString != ""
 			then 
 			(
 				print htmlString
 			)		
 		)
 		fn getWebData sender arg =
 		(
 			try
 			(
 				wrGETURL = (dotnetclass "System.Net.WebRequest").Create(arg.Argument);
 				wrGETURL.proxy = (dotnetclass "System.Net.WebProxy").GetDefaultProxy();
 				wrGETURL.Method = "POST"
 				wrGETURL.ContentType = "application/x-www-form-urlencoded"
 				objStreamWR = wrGETURL.GetRequestStream() -- da eroare cand network disabled, sau cand modemul e inchis sau cand nu lucreaza siteul meu
 				objwriter = dotnetobject "System.IO.StreamWriter" objStreamWR;
 				objwriter.Write("code=001&dd=564");
 				objwriter.Close();
 				response = wrGETURL.GetResponse(); -- da eroare cand pagina mea nu lucreaza, dar siteul meu lucreaza
 				objstream = response.GetResponseStream()
 				objReader = dotnetobject "System.IO.StreamReader" objStream;
 				sLine = "";
 				while sLine != undefined and objReader!=undefined do
 				(
 					sLine = objReader.ReadLine()
 					if sLine != undefined then
 						htmlString += sline
 				)
 			)
 			catch
 			(
 				print "Could Not Connect"
 			)
 		)
 
 		fn WebPageConnect ip = 
 		(
 			local thread = dotnetobject "System.ComponentModel.BackGroundWorker";
 			dotnet.addeventhandler thread "DoWork" getWebData
 			dotNet.addeventhandler thread "RunWorkerCompleted" Completed
 			if not thread.isBusy do 
 			(	
 				thread.RunWorkerAsync ip;
 				thread.IsBusy
 			)	
 		)
 		WebPageConnect "https://example.com/.../index.php"
 )		

Hi try2script,

I can confirm your code works in max 2015 and not in max 2016. If you make the following edit, it will work in max 2016. Replace the objwriter object with this code. Essentially you can just write directly into the request stream and don’t have to use the in-between streamwriter object. To do this you have to convert your string into bytes.

Replace

objwriter = dotnetobject "System.IO.StreamWriter" objStreamWR;
  objwriter.Write("code=001&dd=564");
  objwriter.Close();

with

local dataBytes = (dotnetObject "System.Text.ASCIIEncoding").getbytes "code=001&dd=564"
 objStreamWR.write dataBytes 0 dataBytes.count

Oh, yess! Thank youuu, GrabJacket!
You’re aowsome! Does this code (the new one) work in 2015 now?

Yes it does

It means, it works in 2012,2014,2015 and 2016. (didn’t test in 2013 but I think it will work)

I think many scripts should be updated according to your solution, because most of them are made just like my script from above!

Thank you one more time!