How to download a file

Hello I can’t download a file.

Can you tell me where my mistake is.

Thanck you

My methode

Var tx_file As String

Var url_connect As New URLConnection

Var Requete As String



Requete = "https://www.data.gouv.fr/api/1/datasets/r/4d741143-8331-4b59-95c2-3b24a7bdbe3c"

tx_file = "Données_Immobilières_"  + ".txt"

Var outputFile As FolderItem = SpecialFolder.Documents.Child( tx_file )

url_connect = New URLConnection
url_connect.Send("GET", url , outputFile)

Var h As New URLConnection
h.Send ( "POST" , URL , outputFile )

Exception err
  Break

  //

In desktop app, for downloading you only need a GET, not a POST. A minimal version is (not tested):

Var url As String = “https://www.data.gouv.fr/api/1/datasets/r/4d741143-8331-4b59-95c2-3b24a7bdbe3c”
Var fileName As String = “Données_Immobilières_.txt”
Var outputFile As FolderItem = SpecialFolder.Documents.Child(fileName)

Var conn As New URLConnection
conn.Send(“GET”, url, outputFile)

The POST call and the unused Exception err line can be removed.

Thank you Olivier

Yes POST is initial, it was just a test

My mistake: the downloaded file is a compressed file.

Solution: the file name must be:

Var fileName As String = “Real Estate_Data_.txt” + “.zip”

and not

Var fileName As String = “Real Estate_Data_.txt”

bye

1 Like