Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. URLDownloadToFile is making me mad

URLDownloadToFile is making me mad

Scheduled Pinned Locked Moved C / C++ / MFC
comquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MattyBee
    wrote on last edited by
    #1

    Hi there. Here's a pretty simple program: void main(void) { HRESULT hr = URLDownloadToFile(NULL, "http://www.google.com", "c:\\output.htm", 0, NULL) ; if (SUCCEEDED(hr)) { printf("success\n") ; } else { printf("failed\n") ; } } For some reason the URLDownloadToFile call fails. If I put any of a host of other urls in the call the download works perfectly, however, for www.google.com and several other pages (www.yahoo.es for one) the function just refuses to work. I'm completely baffled by this. I can't find any commonality between the pages that fail and I know that www.google.com does indeed exist on the internet. Has anyone else had problems using the URLDownloadToFile function? Thanks

    M 1 Reply Last reply
    0
    • M MattyBee

      Hi there. Here's a pretty simple program: void main(void) { HRESULT hr = URLDownloadToFile(NULL, "http://www.google.com", "c:\\output.htm", 0, NULL) ; if (SUCCEEDED(hr)) { printf("success\n") ; } else { printf("failed\n") ; } } For some reason the URLDownloadToFile call fails. If I put any of a host of other urls in the call the download works perfectly, however, for www.google.com and several other pages (www.yahoo.es for one) the function just refuses to work. I'm completely baffled by this. I can't find any commonality between the pages that fail and I know that www.google.com does indeed exist on the internet. Has anyone else had problems using the URLDownloadToFile function? Thanks

      M Offline
      M Offline
      Michael Dunn
      wrote on last edited by
      #2

      It would help to know the error returned by URLDownloadToFile(). One possibility is that the server doesn't allow downloads without a proper HTTP_REFERER header, which is not present when using that API. --Mike--    THERE IS NO     THERE IS NO    BUT THERE IS MAGIC PIXIE DUST  BUSINESS GENIE  CODE PROJECT Homepage | RightClick-Encrypt | 1ClickPicGrabber "You have Erica on the brain" - Jon Sagara to me

      B 1 Reply Last reply
      0
      • M Michael Dunn

        It would help to know the error returned by URLDownloadToFile(). One possibility is that the server doesn't allow downloads without a proper HTTP_REFERER header, which is not present when using that API. --Mike--    THERE IS NO     THERE IS NO    BUT THERE IS MAGIC PIXIE DUST  BUSINESS GENIE  CODE PROJECT Homepage | RightClick-Encrypt | 1ClickPicGrabber "You have Erica on the brain" - Jon Sagara to me

        B Offline
        B Offline
        Big Art
        wrote on last edited by
        #3

        I experimented with this method and got the same problem for google and a few other sites. The error code is 0x800401e4 which translates to "Invalid syntax"???? Art

        M 1 Reply Last reply
        0
        • B Big Art

          I experimented with this method and got the same problem for google and a few other sites. The error code is 0x800401e4 which translates to "Invalid syntax"???? Art

          M Offline
          M Offline
          MattyBee
          wrote on last edited by
          #4

          That's right, 0x800401e4 is MK_E_SYNTAX. MSDN describes this error for a different URL Moniker function (they don't even list it as a return value for URLDownloadToFile) and it says: A moniker could not be created because szURL does not correspond to valid URL syntax for a full or partial URL. This is uncommon, because most parsing of the URL occurs during binding and because the syntax for URLs is extremely flexible. So what's going on? I can't believe that I just can't use URLDownloadToFile at all in my application because it just doesn't download certain pages... Also I don't think the problem has to do with a bad header to www.google.com because I can get a response from the google server via telnet by just sending a request line and a "Host" header... They don't seem strangely picky about requiring headers.

          B 1 Reply Last reply
          0
          • M MattyBee

            That's right, 0x800401e4 is MK_E_SYNTAX. MSDN describes this error for a different URL Moniker function (they don't even list it as a return value for URLDownloadToFile) and it says: A moniker could not be created because szURL does not correspond to valid URL syntax for a full or partial URL. This is uncommon, because most parsing of the URL occurs during binding and because the syntax for URLs is extremely flexible. So what's going on? I can't believe that I just can't use URLDownloadToFile at all in my application because it just doesn't download certain pages... Also I don't think the problem has to do with a bad header to www.google.com because I can get a response from the google server via telnet by just sending a request line and a "Host" header... They don't seem strangely picky about requiring headers.

            B Offline
            B Offline
            Big Art
            wrote on last edited by
            #5

            I don't know what is wrong but I tried to get the data using the Internet API functions: InternetOpen(..) InternetOpenUrl(..) InternetReadFile(..) and it works fine for Google and all the other sites I tried. I suggest you go that route. Art

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups