Author Topic: https example available?  (Read 1833 times)

0 Members and 1 Guest are viewing this topic.

Brian Alvarez

  • Guest
https example available?
« on: August 26, 2019, 02:02:41 PM »

 Charles, is there someting in your includes to make https connections to a website and download HTML content?

Charles Pegge

  • Guest
Re: https example available?
« Reply #1 on: August 26, 2019, 04:41:18 PM »
Yes. examples\System\Internet\VerySimpleBrowser.o2bas

Also supports ftp.

It stores the result in t.txt

Code: [Select]


extern lib "wininet.dll"

! InternetOpenA
! InternetOpenUrlA
! InternetCloseHandle
! InternetReadFile

string buf=nuls 0x20000 '128k
string tbuf
string url="https://www.oxygenbasic.org/index.html"
int cbytes
sys hInternet
sys hFile
int c
hInternet = InternetOpenA( "o2demo",0,0,0,0 )
hFile = InternetOpenUrlA( hInternet,url,0,0,0,0 )
do
  cbytes=0
  InternetReadFile( hFile,buf,len(buf),@cbytes )
  if cbytes
    tbuf+=left(buf,cbytes)
    c++
  else
    exit do
  endif
loop
InternetCloseHandle( hFile )
InternetCloseHandle( hInternet )
'print tbuf
putfile( "t.txt",tbuf )
'print c 'count loops


NOTES:
======

'https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-internetopena
'https://docs.microsoft.com/en-us/cpp/mfc/wininet-basics?view=vs-2019#_core_create_a_very_simple_browser


/*
% INTERNET_OPEN_TYPE_DIRECT 1
% INTERNET_FLAG_ASYNC 0x10000000
*/

/*
extern lib "wininet.dll"

sys InternetOpenA(
  LPCSTR lpszAgent,
  DWORD  dwAccessType,
  LPCSTR lpszProxy,
  LPCSTR lpszProxyBypass,
  DWORD  dwFlags
);

BOOLAPI InternetCloseHandle(
  HINTERNET hInternet
);

BOOLAPI InternetCanonicalizeUrlA(
  LPCSTR  lpszUrl,
  LPSTR   lpszBuffer,
  LPDWORD lpdwBufferLength,
  DWORD   dwFlags
);
sys InternetOpenUrlA(
  HINTERNET hInternet,
  LPCSTR    lpszUrl,
  LPCSTR    lpszHeaders,
  DWORD     dwHeadersLength,
  DWORD     dwFlags,
  DWORD_PTR dwContext
);

BOOLAPI InternetReadFile(
  HINTERNET hFile,
  LPVOID    lpBuffer,
  DWORD     dwNumberOfBytesToRead,
  LPDWORD   lpdwNumberOfBytesRead
);

BOOLAPI InternetFindNextFileA(
  HINTERNET hFind,
  LPVOID    lpvFindData
);

*/

'#include <afxinet.h>

/*
void DisplayPage(LPCTSTR pszURL)
{
   CInternetSession session(_T("My Session"));
   CStdioFile* pFile = NULL;
   CHAR szBuff[1024];
   //use a URL and print a Web page to the console
   pFile = session.OpenURL(pszURL);
   while (pFile->Read(szBuff, 1024) > 0)
   {
      printf_s("%1023s", szBuff);
   }
   delete pFile;
   session.Close();
}
*/




Brian Alvarez

  • Guest
Re: https example available?
« Reply #2 on: August 26, 2019, 04:46:25 PM »
Thanks charles, i will study the examples. :)