blog

#include "stdafx.h"
#include "ACCBLOG.h"
#include "afxinet.h"
#include "afx.h"
#include <fstream>
#include <process.h>
#include <vector>
//#include <stdlib.h>
//#include <iostream>

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

#define random(x) (rand()%x)
// 唯一的应用程序对象
static int count = 0;
CWinApp theApp;

using namespace std;
unsigned int  _stdcall testHttp(void *p);
bool  AccessMyBlog(CString strHttpName);
void getBlogUrl();
HANDLE hEvent;
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
 int nRetCode = 0;

 // 初始化 MFC 并在失败时显示错误
 if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
 {
  // TODO: 更改错误代码以符合您的需要
  _tprintf(_T("错误: MFC 初始化失败\n"));
  nRetCode = 1;
 }
 else
 {
  // TODO: 在此处为应用程序的行为编写代码。
  hEvent = CreateEvent(NULL,true,false,NULL);
  getBlogUrl();
  unsigned int a;
  _beginthreadex(NULL,0,testHttp,0,0,&a);

 }

Sleep(5000000000000); 
 return nRetCode;
}


bool  AccessMyBlog(CString strHttpName)
{
 CInternetSession sess; 
 CHttpFile* fileGet; 
 CString strHeaders = "Content-Type: application/x-www-form-urlencoded"; // 请求头  
 try 
 { 
  
  fileGet=(CHttpFile*)sess.OpenURL(strHttpName);//打开文件  
  if(fileGet)
  {
   count++;
   cout<<count<<":访问博客("<<strHttpName<<")成功"<<endl;
  }
  else
  {
   cout<<"访问博客("<<strHttpName<<")失败"<<endl;
  }
 } 
 catch(CException* e) 
 { 
  fileGet = 0; 
  throw; 
 } 
}
//
vector<CString> m_pBlog_vex;
unsigned int  _stdcall testHttp(void *p)
{
 WaitForSingleObject(hEvent,INFINITE);
 vector<CString>::iterator itercsVec = m_pBlog_vex.begin();
 while(1)
 {
  while (itercsVec != m_pBlog_vex.end())
  {
   CString strUrl = *itercsVec;
   AccessMyBlog(strUrl);
   itercsVec++;
   Sleep(10);
  }
  itercsVec = m_pBlog_vex.begin();
  Sleep(random(10)*20);

 }
 return 0;
}


void getBlogUrl()
{
 char *iniBlogUrl = "http://blog.csdn.net";
 char buffer[256];
 ifstream myfile;//
 myfile.open("blog.txt");
 if(myfile)
 {
  while (!myfile.eof() )
  {
   CString myUrl;
   myfile.getline (buffer,256);
   myUrl.Format("%s%s",iniBlogUrl,buffer);
   m_pBlog_vex.push_back(myUrl);
  }   
 }
 myfile.close(); 
 SetEvent(hEvent);
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值