[Closed] DotNet – Internet access
Hey, I have been trying to check a file over the internet using DotNet but I’m having trouble with getting what is returned usable as maxscript code. There also might be a better way to do it than what I’m using, let me know if you have any ideas. Here is what I got so far:
rollout testroll "Web Test" width:580 height:100
(
dotNetControl wb "System.Windows.Forms.WebBrowser" pos:[10,10] width:580 height:100
)
createdialog testroll
testroll.wb.url = dotNetObject "System.Uri" [ http://www.polyboost.com/dotnettest.htm ]( http://www.polyboost.com/dotnettest.htm)
returnstring = testroll.wb.documenttext
When I execute testroll.wb.documenttext manually I get the contents of the file as a string in the listener but when I run it as a script I get an empty string “”. Any help would be aprreciated, what can I do?
CML
rollout testroll "Web Test" width:580 height:100
(
dotNetControl wb "System.Windows.Forms.WebBrowser" pos:[10,10] width:580 height:100
on wb DocumentCompleted arg do
(
returnstring = testroll.wb.documenttext
print returnstring
)
on testroll open do
(
testroll.wb.url = dotNetObject "System.Uri" "http://www.polyboost.com/dotnettest.htm"
)
)
createdialog testroll
You have to wait for the document to load, otherwise documenttext would be empty. The DocumentCompleted handler is called when the loading finishes.
The arg argument to the handler can be very useful to dissect the result.
Calling showProperties and showMethods on arg will provide you with some ideas…
Here is the full list of properties, methods and handlers for this object:
http://www.scriptspot.com/bobo/mxs9/dotNet/dotNetObject_System.Windows.Forms.WebBrowser.html
Hey Bobo, thanks a lot, works fine! Very appreciated. I’ll dig around to see what else I can find.
cheers,
CML
Hmm, maybe I’m missing the point, but why use a full-blown webbrowser component when you could do it with a WebRequest and a streamReader ?
Because I do not know how to use them. I’m pretty new to using DotNet so I’m looking for other alternatives like that. Can you give me a simple example using those commands?
cheers,
CML
As stolen straight from the autodesk forums (was nicer than my own shizzle:D):
requestClass = dotNetClass "System.Net.WebRequest"
request = requestClass.Create("http://sourceforge.net")
request.Method = "GET"
request.Timeout = 5000
response = request.getResponse()
-- response is an HttpWebResponse
responseStream = response.GetResponseStream()
encodingClass = dotNetClass "System.Text.Encoding"
encoding = encodingClass.GetEncoding "utf-8"
readStream = dotNetObject "System.IO.StreamReader" responseStream encoding
readStream.ReadToEnd()
readStream.Close()
response.Close()
Hey Segunda, thanks a lot for the example! I haven’t had time to try it out yet but I will soon.
cheers,
CML