Hello everyone,
I 've been looking for a solution for this problem for some time now but I don't seem to figure it out.
I want to download the source of a web page (the HTML source). I found several API function that have to do something with internet and downloading for example InternetOpen, InternetOpenUrl
.
This didn't work. I tried almost everything but it wouldn't compile.
I found this code on MSDN:
int main(int argc, char* argv[])
{
HINTERNET hNet = ::InternetOpen("MSDN SurfBear",
PRE_CONFIG_INTERNET_ACCESS,
NULL,
INTERNET_INVALID_PORT_NUMBER,
0) ;
HINTERNET hUrlFile = ::InternetOpenUrl(hNet,
"http://www.microsoft.com",
NULL,
0,
INTERNET_FLAG_RELOAD,
0) ;
char buffer[10*1024] ;
DWORD dwBytesRead = 0;
BOOL bRead = ::InternetReadFile(hUrlFile,
buffer,
sizeof(buffer),
&dwBytesRead);
::InternetCloseHandle(hUrlFile) ;
::InternetCloseHandle(hNet) ;
return 0;
}
It keeps giving me the following errors:
--------------------Configuration: internetopen - Win32 Debug--------------------
Linking...
internetopen.obj : error LNK2001: unresolved external symbol __imp__InternetCloseHandle@4
internetopen.obj : error LNK2001: unresolved external symbol __imp__InternetReadFile@16
internetopen.obj : error LNK2001: unresolved external symbol __imp__InternetOpenUrlA@24
internetopen.obj : error LNK2001: unresolved external symbol __imp__InternetOpenA@20
Debug/internetopen.exe : fatal error LNK1120: 4 unresolved externals
Error executing link.exe.
internetopen.exe - 5 error(s), 0 warning(s)
One project I downloaded does work. A bit. It downloads the first several lines of the source and then just outputs fffffffffffffffffffffffffffffffff (it the buffer gets filler with ff-s after the first lines of source).
Also this is an MFC project, and I prefer not using MFC.
I'll post the MFC code below:
void CMFCinternetDlg::OnButton1()
{
// TODO: Add your control notification handler code here
CInternetSession* pInternetSession;
pInternetSession = new CInternetSession();
if (!pInternetSession)
{
MessageBox("Could not establish HTTP session, please check your connection","error");
return;
}
CStdioFile* pFile = NULL;
char* buffer;
buffer = new char[30000];
pFile = pInternetSession->OpenURL(CString("http://www.my-url.com"));
pFile->Read(buffer, 30000);
ofstream myfile;
myfile.open ("example.txt");
myfile << buffer;
myfile.close();
pFile->Close();
pInternetSession->Close();
}
Well, this is what I've tried so far, but as I told before no succes.
I would greatly appreciate it if anyone could point me in the right direction.
Greetz, Eddy