Date: 02-16-2022
Return to Index
created by gbSnippets
'Sometimes you only want information about a file, not the entire file itself.
'To get only the header lines - not the body of a file - use the HEAD
'method instead of the usual GET. Here's the minimum code:
'Primary Code:
'Here's the minimum code, using HEAD instead of the usual GET in
'an HTTP session.
Tcp Open "HTTP" AT "www.garybeene.com" AS #1 TIMEOUT 60000
Tcp Print #1, "HEAD http://www.garybeene.com/files/tcp_test.txt HTTP/1.0"
Tcp Print #1, ""
Tcp Recv #1, 4096, Buffer$
Tcp Close #1
'Here's the HTTP response you'd get from the code above - just the header lines.
HTTP/1.1 200 OK
Date: Thu, 01 Oct 2009 03:02:37 GMT
Server: Apache
Last-Modified: Thu, 01 Oct 2009 02:19:54 GMT
ETag: "b24f18a-24-474d648708680"
Accept-Ranges: bytes
Content-Length: 36
Connection: Close
Content-Type: Text/plain
'Compilable Example: (Jose Includes)
' Client TCP/IP example - retrieve a web page
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
Global hDlg as Dword
Function PBMain() As Long
Dialog New Pixels, 0, "Test Code",300,300,200,200, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, 100,"Push", 50,10,100,20
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
If CB.Msg = %WM_Command AND CB.Ctl = 100 AND CB.Ctlmsg = %BN_Clicked Then
Local Buffer$
Tcp Open "HTTP" AT "www.garybeene.com" AS #1 TIMEOUT 60000
Tcp Print #1, "HEAD http://www.garybeene.com/files/tcp_test.txt HTTP/1.0"
Tcp Print #1, ""
Tcp Recv #1, 4096, Buffer$
Tcp Close #1
MsgBox Buffer$
End If
End Function
'gbs_00373
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm