[Closed] dotNet webClient
webClient=dotNetObject "system.net.webClient"
webClient.downLoadString "some path"
When using the above is there some way to check if there is a connection to the web and if the path is then valid to the file? At the moment I’m just going with a try()catch().
In max you can use:
internet.CheckConnection()
which will also take a URL: argument, but I’m not sure it’s very reliable, I can get it to return true for urls that don’t exist…perhaps it just means a connection is active, not the site?
Hey Paul, have you checked the System.Uri?
I’ve used it in the past and I think it does what you need:
theUri=dotnetObject “System.Uri” “ http://www.paulneale.com/test.zip ”
theValue=theUri.IsFile()
Try this, I havent tried it in max but I think the syntax is correct, it returns true if it’s a file, false otherwise.
Cheers.
Rorschach, Thanks I hadn’t seen that struct before. Looks like that might do it.
Artur, I looked at that but it always returns false since it is no connecting to anything as far as I know. I’m not sure how it would return true unless the URI was a local file. There has to be a dotNet way.
Hmm, why is this returning false? I can’t get it to return true on any url.
internet.CheckConnection url:"http://www.penproductions.ca"
Yeah… like I said it’s a bit suspect… you can use the force:true argument, but once I did that it was reporting true for anything, even made up URLS, even after I put force:false.
No idea whats going on.
I’m trying with system.net.webRequest but it just hangs when it can’t get a connection. Then it errors finaly saying that it has timed out.
sysNet=(dotNetClass "system.net.WebRequest").create "http://penpro.ca"
response=sysNet.GetResponse()
Hi Paul,
Try this:
request = (dotNetClass "system.Net.WebRequest").create "http://www.penproductions.ca"
request.Credentials = (dotnetClass "System.Net.CredentialCache").DefaultCredentials
response = request.GetResponse()
result_URI = response.ResponseUri.ToString()
result_HEADER = response.Headers.ToString()
response.Close()
-Johan
*edit: you need to call close on response otherwise the sockets stay open and the next few calls will give you a timeout.
Thanks Johan, I’ll give that a shot. I might not bother as I think it still takes forever if it can’t find a connection.
Just tried it and this line fails if there is no connection to the web and throws an error.
response = request.GetResponse()