Notifications
Clear all
[Closed] Dotnet > Encoding UTF8
Jan 04, 2015 9:52 pm
I’m making a script that sends information via “POST” using dotNet to a web server. I can be sent to the “String” must convert to UTF8 and so use the properties of ByteArray. But this conversion returns error. For example, I can not use the length parameter after converting it.
this is code:
clearlistener()
fn sendPost =
(
--variables
url = "http://www.explample.com"
sendText = "Send this text"
-- http webrequest
httpRequest = (dotNetClass "system.Net.WebRequest").create (url as string)
[...]
-- encoding text > UTF8
Encoding = DotnetClass "System.Text.Encoding.UTF8"
byteData = Encoding.GetBytes(sendText)
-- send
httpRequest.ContentLength = byteData.Length -- No found length in byteData ?
dataStream = httpRequest.GetRequestStream()
dataStream.Write(byteData, 0, byteData.Length) -- No write but no found length
dataStream.Close()
response = httpRequest.GetResponse()
)
sendPost()
3 Replies
Jan 04, 2015 9:52 pm
max will convert the resulting System.Byte[] into a maxscript array of bytes, which will not have a .length property, but a .count property.
Alternatively, call it like this instead:
byteData = Encoding.GetBytes(sendText) asDotnetObject:on
this will suppress the conversion and return a System.Byte[].