c++ - WinInet 输出中的随机字符

标签 c++ session output wininet

我有以下代码:

#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>¥ )。

最佳答案

你试过这样积累缓冲吗:

cout << std::string(DataReceived, NumberOfBytesRead);

关于c++ - WinInet 输出中的随机字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29491212/

相关文章:

C++ - 使用默认模板作为特化的基础

php - 从登录创建 session 后,避免 php 中的 header 冲突?

java - JOptionPane 输出文本副本

angular - 最佳从 EventEmitter 事件重新进入 ngZone

c - 为什么这段代码会出错?

c++ - 使用 DLL 作为 C++ 游戏 SDK 发布的安全性(dll 已修改,exe 永不修改)

C++ 在程序中运行程序,两次

c++ - 在 std::sort 上使用类方法比较器

php - session 可以在本地主机上运行,​​但不能在服务器上运行(Ipage 等..)

php - 通知 : undefined index with session global