# HTTP download issue

**URL:** <https://forum.xojo.com/t/http-download-issue/15475>\
**Category:** General\
**Created:** [April 4, 2014, 6:16am UTC](https://forum.xojo.com/t/http-download-issue/15475 "2014-04-04T06:16:51Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_Brogdon](https://forum.xojo.com/letter_avatar_proxy/v4/letter/m/e274bd/32.png) [@Michael\_Brogdon](https://forum.xojo.com/u/Michael_Brogdon)\
**Post date:** [April 4, 2014, 6:16am UTC](https://forum.xojo.com/t/http-download-issue/15475/1 "2014-04-04T06:16:51Z")

</div>

I have the following code running in loop. The loop increments numbers that are included in the file name.

If I un-comment the MsgBox line, and dismiss the message after every download, all of the files download properly.

If I comment it out, all of the downloaded files are created, but are 0K (empty) except for the last one.

HTTPSocket last error code is “0.”

I also have MsgBox " Error " + str(code) + " state encountered." in the Error event of the socket, but it never generates a message,

If currentDownloadFile \<\> nil then  
// Asynchronous.  
Socket\_Clone.get(theURL, currentDownloadFile)  
MsgBox Str(Socket\_Clone.LastErrorCode)  
End If

What am I missing?

---

<div class="post-metadata">

**Author:** ![Michael\_Brogdon](https://forum.xojo.com/letter_avatar_proxy/v4/letter/m/e274bd/32.png) [@Michael\_Brogdon](https://forum.xojo.com/u/Michael_Brogdon)\
**Post date:** [April 4, 2014, 6:33am UTC](https://forum.xojo.com/t/http-download-issue/15475/2 "2014-04-04T06:33:05Z")

</div>

It looks like this is not possible without creating an array and using pop or downloading synchronously.

---

<div class="post-metadata">

**Author:** ![Kem\_Tekinay](https://forum.xojo.com/user_avatar/forum.xojo.com/kem_tekinay/32/154_2.png) [@Kem\_Tekinay](https://forum.xojo.com/u/Kem_Tekinay)\
**Post date:** [April 4, 2014, 6:41am UTC](https://forum.xojo.com/t/http-download-issue/15475/3 "2014-04-04T06:41:10Z")

</div>

You are using the asynchronous version of that command, meaning that it returns to your code immediately as it downloads in the background. That would be fine except that you immediately tell it to download the next file, canceling the first.

If you want them all to try to download simultaneously in the background, use an array. Otherwise, provide a timeout so it finishes one download before moving to the next.

```auto
If currentDownloadFile <> nil then
  // Synchronous.
  Socket_Clone.get(theURL, currentDownloadFile, 10)
  MsgBox Str(Socket_Clone.LastErrorCode)
End If
```

---

<div class="post-metadata">

**Author:** ![Kimball\_Larsen](https://forum.xojo.com/user_avatar/forum.xojo.com/kimball_larsen/32/474_2.png) [@Kimball\_Larsen](https://forum.xojo.com/u/Kimball_Larsen)\
**Post date:** [April 4, 2014, 7:48pm UTC](https://forum.xojo.com/t/http-download-issue/15475/4 "2014-04-04T19:48:08Z")

</div>

Or, do it synchronously.

Or, keep it asynchronous, but have the next file start downloading after the first has completed by putting more logic into the DownloadComplete that walks through an array of files to download.

Depending on the number of items you need to download, doing them asynchronously but sequentially is likely the best way to go about it. Otherwise you may hammer the server and ultimately slow ALL the transfers.

---

<div class="post-metadata">

**Author:** ![system](https://forum.xojo.com/uploads/default/original/1X/455b4dcc0e61630e9f81940004ddffa49c432a46.png) [@system](https://forum.xojo.com/u/system)\
**Post date:** [October 29, 2020, 5:09pm UTC](https://forum.xojo.com/t/http-download-issue/15475/5 "2020-10-29T17:09:29Z")

</div>


