It is currently Tue Mar 09, 2021 8:35 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: ReceiveHTTPFile
PostPosted: Sun Dec 20, 2020 7:46 pm 
Offline
User
User

Joined: Sun Jul 24, 2016 11:54 pm
Posts: 51
Is this normal? there is no file like that. But i recieve 1. Whatever i write there as file name... such as http://armasoft.net/... i always get result positive... How can i get normal result? I need true or false?

InitNetwork()
a=ReceiveHTTPFile("http://armasoft.net/xxx","/home/arma/TEST")
Debug a


Top
 Profile  
Reply with quote  
 Post subject: Re: ReceiveHTTPFile
PostPosted: Sun Dec 20, 2020 10:19 pm 
Offline
Addict
Addict
User avatar

Joined: Tue Oct 09, 2007 2:15 am
Posts: 1156
If there is no file .... you get the server error page, like 404-Page....
So a #True result is normal, ReceiveHTTPFile download something.

_________________
PureBasic 5.72 LTS (Windows x86/x64) | Windows10 Pro x64 | Z370 Extreme4 | i7 8770k | 64GB RAM | iChill GeForce RTX 2080 Super | HAF XF Evo​​
English is not my native language... (I often use DeepL to translate my texts.)


Top
 Profile  
Reply with quote  
 Post subject: Re: ReceiveHTTPFile
PostPosted: Mon Dec 21, 2020 12:13 am 
Offline
User
User

Joined: Sun Jul 24, 2016 11:54 pm
Posts: 51
Then what is the result meaning?
There is an help on document...

Example

InitNetwork()

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

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

It says always Success... Never says Failed... What a strange :(


Top
 Profile  
Reply with quote  
 Post subject: Re: ReceiveHTTPFile
PostPosted: Mon Dec 21, 2020 12:30 am 
Offline
Addict
Addict
User avatar

Joined: Tue Oct 09, 2007 2:15 am
Posts: 1156
Because it is download this page, that comes with this url....

on your first try it downloads the error page, so 1 is ok.
0 is the result, if nothing is downloaded to your computer!

_________________
PureBasic 5.72 LTS (Windows x86/x64) | Windows10 Pro x64 | Z370 Extreme4 | i7 8770k | 64GB RAM | iChill GeForce RTX 2080 Super | HAF XF Evo​​
English is not my native language... (I often use DeepL to translate my texts.)


Top
 Profile  
Reply with quote  
 Post subject: Re: ReceiveHTTPFile
PostPosted: Mon Dec 21, 2020 7:25 am 
Offline
User
User

Joined: Sun Jul 24, 2016 11:54 pm
Posts: 51
For me this is nothing useful... Some thing like bug... How can i detect if successfully download or not... and Why?
I solve my situation but this command works as stupid. I use wget now... It says error if there is no file to download. So i solve my problem. But in my oppinion this is wrong. If it will always says True... When will it say False? And what is it for?


Top
 Profile  
Reply with quote  
 Post subject: Re: ReceiveHTTPFile
PostPosted: Mon Dec 21, 2020 10:59 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sat Jun 28, 2003 12:01 am
Posts: 531
You have to do a HTTPRequest first and check the HTTP status code.
Here an untested code:
Code:
Procedure ReceiveHTTPFileX(URL.s, Filename.s, Flags=#PB_Ignore, UserAgent.s=#Empty$)
   Protected httpReq, httpStatus
   httpReq = HTTPRequest(#PB_HTTP_Get, URL, #Null$, #PB_HTTP_HeadersOnly)
   If httpReq
      httpStatus = Val(HTTPInfo(httpReq, #PB_HTTP_StatusCode))
      FinishHTTP(httpReq)
      If httpStatus = 200
         If UserAgent <> #Empty$
            ProcedureReturn ReceiveHTTPFile(URL, Filename, Flags, UserAgent)
         ElseIf Flags <> #PB_Ignore
            ProcedureReturn ReceiveHTTPFile(URL, Filename, Flags)
         Else
            ProcedureReturn ReceiveHTTPFile(URL, Filename)
         EndIf
      Else
         ; HTTP request failed
         ProcedureReturn #Null
      EndIf
   Else
      ; Http request failed
      ProcedureReturn #Null
   EndIf
EndProcedure

Maybe the helps to think about the problem ...

_________________
Windows 10 / Windows 7
PB Last Final / Last Beta Testing


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

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 4 guests


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