ReceiveHTTPFile

Just starting out? Need help? Post your questions and find answers here.
arma
User
User
Posts: 57
Joined: Sun Jul 24, 2016 11:54 pm

ReceiveHTTPFile

Post by arma »

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
User avatar
Bisonte
Addict
Addict
Posts: 1226
Joined: Tue Oct 09, 2007 2:15 am

Re: ReceiveHTTPFile

Post by Bisonte »

If there is no file .... you get the server error page, like 404-Page....
So a #True result is normal, ReceiveHTTPFile download something.
PureBasic 6.04 LTS (Windows x86/x64) | Windows10 Pro x64 | Asus TUF X570 Gaming Plus | R9 5900X | 64GB RAM | GeForce RTX 3080 TI iChill X4 | HAF XF Evo | build by vannicom​​
English is not my native language... (I often use DeepL to translate my texts.)
arma
User
User
Posts: 57
Joined: Sun Jul 24, 2016 11:54 pm

Re: ReceiveHTTPFile

Post by arma »

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 :(
User avatar
Bisonte
Addict
Addict
Posts: 1226
Joined: Tue Oct 09, 2007 2:15 am

Re: ReceiveHTTPFile

Post by Bisonte »

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 6.04 LTS (Windows x86/x64) | Windows10 Pro x64 | Asus TUF X570 Gaming Plus | R9 5900X | 64GB RAM | GeForce RTX 3080 TI iChill X4 | HAF XF Evo | build by vannicom​​
English is not my native language... (I often use DeepL to translate my texts.)
arma
User
User
Posts: 57
Joined: Sun Jul 24, 2016 11:54 pm

Re: ReceiveHTTPFile

Post by arma »

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?
User avatar
helpy
Enthusiast
Enthusiast
Posts: 552
Joined: Sat Jun 28, 2003 12:01 am

Re: ReceiveHTTPFile

Post by helpy »

You have to do a HTTPRequest first and check the HTTP status code.
Here an untested code:

Code: Select all

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
Post Reply