我有以下代码:
#include <wininet.h>
#include <cstdlib>
#include <iostream>
#include <windows.h>
#include <string.h>
using namespace std;
int main(int argc, char *argv[])
{
HINTERNET connect = InternetOpen("MyBrowser",INTERNET_OPEN_TYPE_PRECONFIG,NULL, NULL, 0);
if(!connect){
cout<<"Connection Failed or Syntax error";
return 0;
}
HINTERNET OpenAddress = InternetOpenUrl(connect,"http://shahriar.byethost9.com/com2.html", NULL, 0, INTERNET_FLAG_PRAGMA_NOCACHE|INTERNET_FLAG_KEEP_CONNECTION, 0);
if ( !OpenAddress )
{
DWORD ErrorNum = GetLastError();
cout<<"Failed to open URL \nError No: "<<ErrorNum;
InternetCloseHandle(connect);
return 0;
}
char DataReceived[4096];
DWORD NumberOfBytesRead = 0;
while(InternetReadFile(OpenAddress, DataReceived, 4096, &NumberOfBytesRead) && NumberOfBytesRead )
{
cout << DataReceived;
}
InternetCloseHandle(OpenAddress);
InternetCloseHandle(connect);
cin.get();
system("PAUSE");
return EXIT_SUCCESS;
}
它获取http://shahriar.byethost9.com/com2.html的源代码并打印到控制台。
问题是,我的页面的源代码是<h5>paint</h5>
,但是程序是打印的:<h5>paint</h5>¥
(每次编辑页面源代码时,最后一个字符都是不同的)。
在编辑了我的页面源代码之后,它变成了:<h5>mspaint</h5>
,但是程序再次打印了旧的源代码(<h5>paint</h5>¥
)。
发布于 2015-04-07 15:26:52
您是否试图以这样的方式积累缓冲区:
cout << std::string(DataReceived, NumberOfBytesRead);
https://stackoverflow.com/questions/29491212
复制相似问题