# Include <stdio. h>
# Include <windows. h>
# Include <wininet. h>
# Define Max size 1024
# Pragma comment (lib, "Wininet. lib ")
Void urlopen (TCHAR *);
Int main (int argc, TCHAR * argv [])
{
TCHAR ch [] = TEXT ("http://dt.163.com/images/news/0605/news02053101_5.jpg ");
Urlopen (ch );
Getchar ();
Return 0;
}
Void urlopen (TCHAR * url)
{
HINTERNET hSession = InternetOpen (TEXT ("UrlTest"), INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY, NULL, NULL, 0 );
If (hSession! = NULL)
{
HINTERNET hHttp = InternetOpenUrl (hSession, url, NULL, 0, INTERNET_FLAG_DONT_CACHE, 0 );
BYTE Temp [MAXSIZE];
ULONG Number = 1;
DWORD written;
HANDLE hFile;
If (hHttp! = NULL)
{
Wprintf_s (TEXT ("% s \ n"), url );
HFile = CreateFile (TEXT ("ysl.jpg"), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0 );
If (hFile = INVALID_HANDLE_VALUE)
{
Goto hear;
}
While (Number> 0)
{
InternetReadFile (hHttp, Temp, MAXSIZE-1, & Number );
Temp [Number] = '\ 0 ';
WriteFile (hFile, Temp, Number, & written, NULL );
}
InternetCloseHandle (hHttp );
HHttp = NULL;
}
Hear:
CloseHandle (hFile );
InternetCloseHandle (hSession );
HSession = NULL;
}
}
Author: yuanweihuayan