Date: 02-16-2022
Return to Index
created by gbSnippets
'The header and body of an HTTP response is separated by two $crlf
'character pairs, making it easy to separate the two.
'Primary Code:
sHeader = Extract$(sDataFromHTTPServer, $CRLF + $CRLF)
sBody = Remain$(sDataFromHTTPServer, $CRLF + $CRLF)
'Compilable Example: (Jose Includes)
'I have a small, two-line file called "tcp_test.txt" on my server that is
'used in this example.
#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, "GET http://www.garybeene.com/files/tcp_test.txt HTTP/1.0"
Tcp Print #1, ""
Tcp Recv #1, 4096, Buffer$
Tcp Close #1
'display header
MsgBox Extract$(Buffer$, $CRLF + $CRLF)
'display body
MsgBox Remain$(Buffer$, $CRLF + $CRLF)
End If
End Function
'gbs_00370
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm