?? httprequest.h
字號:
//#include "stdafx.h"
#include <fstream>
#include <string>
#include <windows.h>
#include <wininet.h>
#pragma once
#include "log.h"
#pragma comment(lib,"version")
#pragma comment(lib,"Wininet.lib")
using namespace std;
//讀取HTTP服務器上面的文件到本地
bool getHTTPFile(const string webfile, string &strRet, const unsigned int port)
{
HINTERNET hINet = ::InternetOpen("Get_File", PRE_CONFIG_INTERNET_ACCESS,
NULL, INTERNET_INVALID_PORT_NUMBER, 0) ;
if (!hINet){
Log("初始化Wininet.dll失敗,可能是Wininet.dll已經損壞!");
return false;
}
HINTERNET hUrlFile = ::InternetOpenUrl(hINet, webfile.c_str(), NULL, 0, INTERNET_FLAG_RELOAD, 0) ;
if (!hUrlFile) {
InternetCloseHandle(hUrlFile);
Log("連接服務器失敗,請確認網絡連接已經打開并且服務器已經打開!" );
return false;
}
char buffer[4*1024] ={0} ;
DWORD dwBytesRead = 0;
BOOL bRead = ::InternetReadFile(hUrlFile, buffer, sizeof(buffer), &dwBytesRead);
if (!bRead) {
InternetCloseHandle(hUrlFile);
InternetCloseHandle(hINet);
Log("發送請求至服務器失敗,請確認網絡連接已經打開并且服務器已經打開!" );
return false;
}
strRet = buffer;
InternetCloseHandle(hINet);
//the code below is determine the server has the file or not
//it may be work,but it's too ugly and dirty,who fix it?!
static const basic_string <char>::size_type npos = -1;//page cannot be found
basic_string <char>::size_type ret1=strRet.find("page cannot be found");
basic_string <char>::size_type ret2=strRet.find("無法找到網頁");
if (ret1!=npos||ret2!=npos)
//if (dwTotal==4040)
{
Log("服務器上沒有要找的文件!");
return false;
}
return true;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -