Code archives/Networking/HttpGet(server,path,port,proxy,proxyport)

This code has been declared by its author to be Public Domain code.

Download source code

HttpGet(server,path,port,proxy,proxyport) by skn32004
Simple function that lets you connect to a web address via httpget. Using a proxy server, if required!
;example of non proxy http get
tcp = HttpGet("www.blitzbasic.com","/Home/_index_.php")
If tcp = False RuntimeError "unable to connect to address"
While Eof(tcp) = False
	DebugLog ReadLine$(tcp)
Wend
CloseTCPStream(tcp)

;example of using a proxy server
tcp = HttpGet("www.blitzbasic.com","/Home/_index_.php",80,"planet1.scs.cs.nyu.edu",3128)
If tcp = False RuntimeError "unable to connect to address"
While Eof(tcp) = False
	DebugLog ReadLine$(tcp)
Wend
CloseTCPStream(tcp)


;function
Function HttpGet(server$,path$,port=80,proxy$="",proxyport=0)
	Local www
	If Len(proxy$) = 0 proxy$ = server$
	If proxyport = 0 proxyport = port
	www = OpenTCPStream(proxy$,proxyport)
	If www = False Return False
	WriteLine www,"GET http://" + server$ + ":" + port + path$ + " HTTP/1.1" + Chr$(13)+Chr$(10) + "Host: " + server$ + Chr$(13)+Chr$(10) + "User-Agent: blitzbasic" + Chr$(13)+Chr$(10) + "Accept: */*" + Chr$(13)+Chr$(10)
	Return www
End Function

Comments

None.

Code Archives Forum