5.43 - ReceiveHTTPFile error

Just starting out? Need help? Post your questions and find answers here.
TerryHough
Enthusiast
Enthusiast
Posts: 781
Joined: Fri Apr 25, 2003 6:51 pm
Location: NC, USA
Contact:

5.43 - ReceiveHTTPFile error

Post by TerryHough »

When the file to be received does not exist, Vs 5.4+ are returning a 1 (success) when it should return a 0 (failure).

Version up through 5.31 return a 0 if the requested file does not exist, as expected and described in the Help file.
Return value

Returns nonzero if the download was successful, zero otherwise. If #PB_HTTP_Asynchronous was specified, it returns the 'HttpConnection' value needed for HTTPProgress(), AbortHTTP() and FinishHTTP().
I tested with Vs 5.41 and 5.43, and 5.50 and they return a 1 (success) and store a file instead

Try this code

Code: Select all

  InitNetwork()
  Filename$ = "C:\Temp\TestFile.jpg"
  Result = ReceiveHTTPFile("http://www.purebasic.com/TestFile.jpg", Filename$)
  If Result
    MessageRequester("Debug", "ReceiveHTTPFile return a " + Str(result), #MB_ICONINFORMATION)
  Else
    MessageRequester("Debug", "ReceiveHTTPFile return a " + Str(result), #MB_ICONERROR)
  EndIf
  End 
The file to be received DOES NOT exist, so the ReceiveHTTPFile command should return a 0. Instead it returns a 1.
And it actually stores a file containing

Code: Select all

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL /TestFile.jpg was not found on this server.</p>
<hr>
<address>Apache/2.2.22 (Debian) Server at www.purebasic.com Port 80</address>
</body></html>
Last edited by TerryHough on Tue Oct 25, 2016 5:40 pm, edited 3 times in total.
Deluxe0321
User
User
Posts: 69
Joined: Tue Sep 16, 2008 6:11 am
Location: ger

Re: 5.43 - ReceiveHTTPFile error

Post by Deluxe0321 »

Hi,
the previous implementation was wrong. I assume this is a simple change introduced by including libcurl into PureBasic.

ReceiveHTTPFile is now working as it should.

See:
https://tools.ietf.org/html/rfc7231#section-6.5
and:
https://tools.ietf.org/html/rfc7231#section-6.5.4

The Procedure does nothing else than downloading the body of a HTTP GET response and storing it at the defined location.

I can confirm that it would be nice to check the header status before storing the data - without using ReceiveHTTPHeader() to check the status before - but there is currently no other way.
You may use libcurl directly: http://www.purebasic.fr/english/viewtop ... ibcurl.lib

Thank you!
Fred
Administrator
Administrator
Posts: 16686
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: 5.43 - ReceiveHTTPFile error

Post by Fred »

Yes, it's the expected behaviour, as you may want to get info from the website if a file doesn't exists.
Post Reply