It is currently Mon Jun 17, 2019 11:52 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: ReceiveHTTPFile in docs
PostPosted: Tue Jan 01, 2019 6:00 am 
Offline
Addict
Addict

Joined: Fri Aug 28, 2015 6:10 pm
Posts: 853
Location: Portugal
Copied this code from DOCS

Code:
  InitNetwork()

  Filename$ = SaveFileRequester("Where to save index.php ?", "", "", 0)

  If ReceiveHTTPFile("http://www.purebasic.com/index.php", Filename$)
    Debug "Success"
  Else
    Debug "Failed"
  EndIf



Works very well. Changed the filename index.php to index.not which I assume does not exist. On the surface everything is fine the programme runs and creates a file on the disk which is not empty. It reports success in both cases but the second file when opened with notepad shows file does not exist.

ReceiveHTTPFile is obviously being fooled into thinking it has the file but it has not. Can the docs be amended to show that you need to check the downloaded file?

Regards

CD

_________________
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.


Top
 Profile  
Reply with quote  
 Post subject: Re: ReceiveHTTPFile in docs
PostPosted: Tue Jan 01, 2019 6:36 am 
Offline
Addict
Addict

Joined: Mon Feb 16, 2015 2:49 pm
Posts: 1882
Well, it did receive a file - the site's 404 page (not an empty file). So the command was a success because a file request was served and downloaded. But how will the user know if that's the intended file? There's simply no way possible to determine that - unless you know what the file content is before you even get it. I guess you could parse the downloaded file for any "404" text?


Top
 Profile  
Reply with quote  
 Post subject: Re: ReceiveHTTPFile in docs
PostPosted: Tue Jan 01, 2019 11:44 am 
Offline
Addict
Addict

Joined: Fri Aug 28, 2015 6:10 pm
Posts: 853
Location: Portugal
I have got over the little problem by checking the file exists before I start the download using this:-
Code:
 

Header = GetHTTPHeader(url)
 
  If FindString(Header,"Not Found") > 0
   
    ProcedureReturn -1
   
  EndIf


You can also do the same thing with a downloaded file by opening and checking the first few lines.

The question is can a note or something be placed in the docs telling newbies like me that this can happen?

Regards

CD

_________________
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.


Top
 Profile  
Reply with quote  
 Post subject: Re: ReceiveHTTPFile in docs
PostPosted: Tue Jan 01, 2019 2:26 pm 
Offline
Addict
Addict
User avatar

Joined: Tue Mar 02, 2004 1:20 pm
Posts: 1008
Location: Amphibios 9
@collectordave: I would rather use HTTPInfo()

Greetings ... Peter

_________________
Can't decide if i need a hug, an XXL coffee, 6 shots of vodka or 2 weeks of sleep.


Top
 Profile  
Reply with quote  
 Post subject: Re: ReceiveHTTPFile in docs
PostPosted: Wed Jan 02, 2019 2:19 am 
Offline
Addict
Addict

Joined: Mon Feb 16, 2015 2:49 pm
Posts: 1882
BTW, this is why on my websites, the files I download are wrapped in [[ and ]] brackets. I then just check if the received file starts and ends with those brackets, and if so, then I know the file was downloaded correctly.


Top
 Profile  
Reply with quote  
 Post subject: Re: ReceiveHTTPFile in docs
PostPosted: Fri Jan 11, 2019 10:00 pm 
Offline
PureBasic Team
PureBasic Team
User avatar

Joined: Fri Apr 25, 2003 6:14 pm
Posts: 1687
Location: Germany (Saxony, Deutscheinsiedel)
This is probably worth a 'remark' in the PB docs.

Anyone with a good idea / text suggestion? Thanks 8)

_________________
Bye,
...André
(PureBasicTeam::Docs & Support - PureArea.net | Order:: PureBasic | PureVisionXP)


Top
 Profile  
Reply with quote  
 Post subject: Re: ReceiveHTTPFile in docs
PostPosted: Sat Jan 12, 2019 6:19 am 
Offline
Addict
Addict

Joined: Fri Aug 28, 2015 6:10 pm
Posts: 853
Location: Portugal
HTTP is qute a thing for newbies. I have seen a few posts on the forum about various aspects.

So rather than a note why not an example programme using some of the standard bits in PB such as download a single file from the internet with progress. I have posted one somewhere using header with no call backs or fancy code and cross platform etc. just need to comment it correctly.

Would answer lots of newbie questions.

_________________
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.


Top
 Profile  
Reply with quote  
 Post subject: Re: ReceiveHTTPFile in docs
PostPosted: Sat Jan 12, 2019 9:53 am 
Offline
Addict
Addict
User avatar

Joined: Thu Jun 07, 2007 3:25 pm
Posts: 3572
Location: Berlin, Germany
Andre wrote:
This is probably worth a 'remark' in the PB docs.

Anyone with a good idea / text suggestion? Thanks 8)

Maybe just change the Debug messages in the example code accordingly, e.g. something like this:
Code:
InitNetwork()

Filename$ = SaveFileRequester("Where to save the received file?", "", "", 0)

If ReceiveHTTPFile("http://www.purebasic.com/index.php3", Filename$)
   Debug "Any file received. If the wanted file doesn't exist, then the received file probably contains an error message."
Else
   Debug "No file received at all."
EndIf

_________________
Please excuse my flawed English. My native language is PureBasic.
Search
RSBasic's backups


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: Exabot [Bot] and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye