TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: TopoWAR on October 06, 2011, 12:49:57 PM

Title: Download file from internet
Post by: TopoWAR on October 06, 2011, 12:49:57 PM
Hi Everyone! Is there any way to download a file online? for example, "http://www.opendcl.com/version/version.txt"
thanks
Title: Re: Download file from internet
Post by: Lee Mac on October 06, 2011, 12:53:16 PM
See here (http://www.theswamp.org/index.php?topic=33750) and here (http://www.theswamp.org/index.php?topic=15188.msg184371#msg184371).
Title: Re: Download file from internet
Post by: VovKa on October 06, 2011, 01:04:27 PM
you don't have to save the file just to know the odcl's version
Code: [Select]
(defun vk_GetRemoteText (RemoteFileName / objHTTP Result)
    (if (setq objHTTP (vlax-create-object "WinHTTP.WinHTTPRequest.5.1"))
        (progn (setq
                   Result (vl-catch-all-apply
                              (function
                                  (lambda ()
                                      (vlax-invoke-method
                                          objHTTP       "Open"
                                          "GET"         RemoteFileName
                                          :vlax-false
                                         )
                                      (vlax-invoke objHTTP "Send")
                                      (vlax-get-property objHTTP "ResponseText")
                                  )
                              )
                          )
               )
               (vlax-release-object objHTTP)
               (if (not (vl-catch-all-error-p Result))
                   Result
               )
        )
    )
)
;;;(vk_GetRemoteText "http://www.opendcl.com/version/version.txt")
Title: Re: Download file from internet
Post by: alanjt on October 06, 2011, 01:21:55 PM
you don't have to save the file just to know the odcl's version
wow  :kewl:
Title: Re: Download file from internet
Post by: ronjonp on October 06, 2011, 01:24:35 PM
That is cool  8-)
Title: Re: Download file from internet
Post by: Lee Mac on October 06, 2011, 01:27:49 PM
you don't have to save the file just to know the odcl's version

Not sure if this applies to the WinHTTP Object, but here (http://www.theswamp.org/index.php?topic=39491.0) I found the XMLHTTP Object seemed to cache the result when using the "GET" keyword, so you may want to use the "POST" operator.

Lee
Title: Re: Download file from internet
Post by: TopoWAR on October 06, 2011, 02:14:17 PM
by teachers, great code!! :lol:
Title: Re: Download file from internet
Post by: VovKa on October 06, 2011, 05:01:27 PM
i share with pleasure, thanks


Not sure if this applies to the WinHTTP Object, but here (http://www.theswamp.org/index.php?topic=39491.0) I found the XMLHTTP Object seemed to cache the result when using the "GET" keyword, so you may want to use the "POST" operator.
Lee
i can't say anything for sure, know nothing about http
i've just googled this http://www.cs.tut.fi/~jkorpela/forms/methods.html (http://www.cs.tut.fi/~jkorpela/forms/methods.html)
there is a paragraph about "caching" but as i've understood it's about cahing a request on a server not a local file
Title: Re: Download file from internet
Post by: Lee Mac on October 06, 2011, 05:53:41 PM
Not sure if this applies to the WinHTTP Object, but here (http://www.theswamp.org/index.php?topic=39491.0) I found the XMLHTTP Object seemed to cache the result when using the "GET" keyword, so you may want to use the "POST" operator.
Lee
i can't say anything for sure, know nothing about http
i've just googled this http://www.cs.tut.fi/~jkorpela/forms/methods.html (http://www.cs.tut.fi/~jkorpela/forms/methods.html)
there is a paragraph about "caching" but as i've understood it's about cahing a request on a server not a local file

That's an interesting link, I shall have to take some time to read it more thoroughly.

I remember reading the following from here (http://msdn.microsoft.com/en-us/library/ms536648%28v=VS.85%29.aspx):
Quote from: MSDN
Internet Explorer caches the results of HTTP GET requests in the Temporary Internet Files (TIF) folder. In most cases, caching improves performance for data that will not change frequently. To guarantee that the results are not cached, use POST.

I noticed this caching when testing my Internet Time function, so thought I'd make you aware of the possibility.

At least, if a similar issue arises in the future you will know what to do :-)
Title: Re: Download file from internet
Post by: Harrie on October 07, 2011, 04:53:21 AM
Hi Everyone! Is there any way to download a file online? for example, "http://www.opendcl.com/version/version.txt"
thanks
I know there was a topic to download the BBC news and the BCC weather forecast into the drawing,
but I can’t find it.

Lee your Internet Time function, is this giving the current internet date and time?
Title: Re: Download file from internet
Post by: Lee Mac on October 07, 2011, 07:09:03 AM
Hi Everyone! Is there any way to download a file online? for example, "http://www.opendcl.com/version/version.txt"
thanks
I know there was a topic to download the BBC news and the BCC weather forecast into the drawing,
but I can’t find it.

http://www.theswamp.org/index.php?topic=37107 (http://www.theswamp.org/index.php?topic=37107)

 :-)
Title: Re: Download file from internet
Post by: TopoWAR on October 07, 2011, 10:15:58 AM
code only works for text files, is this true ?
Is there some code that works for example with jpg or rar ?
Title: Re: Download file from internet
Post by: Lee Mac on October 07, 2011, 10:25:03 AM
code only works for text files, is this true ?
Is there some code that works for example with jpg or rar ?

See my earlier links above.
Title: Re: Download file from internet
Post by: VovKa on October 07, 2011, 12:22:54 PM
code only works for text files, is this true ?
true, what do you expect from function named "vk_GetRemoteText"? :)
Title: Re: Download file from internet
Post by: Harrie on October 09, 2011, 03:53:29 PM
Hi Everyone! Is there any way to download a file online? for example, "http://www.opendcl.com/version/version.txt"
thanks
I know there was a topic to download the BBC news and the BCC weather forecast into the drawing,
but I can’t find it.

http://www.theswamp.org/index.php?topic=37107 (http://www.theswamp.org/index.php?topic=37107)

 :-)
Thanks Lee,

Your Internet Time function, is this giving the current internet date and time?
Title: Re: Download file from internet
Post by: Lee Mac on October 09, 2011, 05:41:59 PM
Your Internet Time function, is this giving the current internet date and time?

Yes, the data is sourced from the NIST time server, the time is expressed in UTC (http://en.wikipedia.org/wiki/UTC) (Coordinated Universal Time).