PDA

View Full Version : DotNet - Internet access


Rivendale
02-28-2007, 04:55 PM
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
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

Bobo
03-01-2007, 02:37 AM
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

Rivendale
03-01-2007, 10:12 AM
Hey Bobo, thanks a lot, works fine! Very appreciated. I'll dig around to see what else I can find.

cheers,
CML

segunda
03-01-2007, 09:21 PM
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 ?

Rivendale
03-01-2007, 11:13 PM
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

segunda
03-02-2007, 08:47 AM
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()

Rivendale
03-06-2007, 12:51 AM
Hey Segunda, thanks a lot for the example! I haven't had time to try it out yet but I will soon.

cheers,
CML

CGTalk Moderation
03-06-2007, 12:51 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.