文件地址为“http://www.baidu.com/xxx.txt”
- // readTxt.cpp :Defines the entry point for the console application.
- //
-
- #include "stdafx.h"
- #include <Windows.h>
- #include <wininet.h>
- #include <string>
- using namespace std;
- #pragma comment(lib, "wininet.lib")
- #define BUF_SIZE 1024
-
- LPSTR GetInterNetURLText(LPSTR lpcInterNetURL, char* buff);
-
- int _tmain(int argc, _TCHAR* argv[])
- {
- char buf[BUF_SIZE] = {0};
- char url[MAX_PATH] = "http://www.baidu.com/xxx.txt";
- GetInterNetURLText(url, buf);
-
- return 0;
- }
-
- LPSTR GetInterNetURLText(LPSTR lpcInterNetURL, char* buff)
- {
- HINTERNET hSession;
- LPSTR lpResult = NULL;
- hSession = InternetOpen("WinInet", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
- __try
- {
- if(hSession != NULL)
- {
- HINTERNET hRequest;
- hRequest = InternetOpenUrlA(hSession,lpcInterNetURL, NULL,0, INTERNET_FLAG_RELOAD, 0);
- __try
- {
- if(hRequest != NULL)
- {
- DWORD dwBytesRead;
- char szBuffer[BUF_SIZE] = {0};
-
- if(InternetReadFile(hRequest, szBuffer, BUF_SIZE, &dwBytesRead))
- {
- RtlMoveMemory(buff, szBuffer, BUF_SIZE);
- return 0;
- }
- }
- }__finally
- {
- InternetCloseHandle(hRequest);
- }
- }
- }__finally
- {
- InternetCloseHandle(hSession);
- }
- return lpResult;
- }
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请
点击举报。