From 5776fd3dcfa2945151e3265336d339010244d8ac Mon Sep 17 00:00:00 2001 From: JZFamily Date: Fri, 3 Nov 2017 19:50:10 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20'CWeatherDataSpider.cpp'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CWeatherDataSpider.cpp | 134 ++++------------------------------------- 1 file changed, 12 insertions(+), 122 deletions(-) diff --git a/CWeatherDataSpider.cpp b/CWeatherDataSpider.cpp index 6e784b7..b1b3ba2 100644 --- a/CWeatherDataSpider.cpp +++ b/CWeatherDataSpider.cpp @@ -12,7 +12,7 @@ #define WEATHER_FORECAST 1 CWeatherDataSpider::CWeatherDataSpider() { - m_strAreaCode = ""; + m_strAreaCode = "天津"; } @@ -22,7 +22,7 @@ CWeatherDataSpider::~CWeatherDataSpider() bool CWeatherDataSpider::GetWeatherDataXml() { - //---------------------------------------- + //------------------创建描述符---------------------- WSADATA wsadata; int ierror = -1; if (ierror = WSAStartup(MAKEWORD(2,2), &wsadata)) @@ -49,12 +49,12 @@ bool CWeatherDataSpider::GetWeatherDataXml() //} //if(connect(sock, (SOCKADDR*)&sa, sizeof(sa))) - // + //连接主机 if (!ConnectHost()) { goto bad; } - // + //发送请求 if (!SendReq()) { goto bad; } - //ջӦ + //接收回应 if (!HandleAck()) { goto bad; } else{ CloseConnect(); return true; } @@ -86,14 +86,14 @@ bool CWeatherDataSpider::CheckIfRecSucceed(char * buf, int nTotalRecv, int nFlag return false; } - //ظǷ200 - //ȡxml + //解析回复是否是200 + //截取xml // std::string strHeadFind =buf; int n =strHeadFind.find("\r\n"); if (-1 != (n = strHeadFind.rfind("200", n))) { return true; } - PosStart = strHeadFind.find("content-length: ");//ñǩ ӿո16ַ + PosStart = strHeadFind.find("content-length: ");//该标签 加空格16个字符 PosStart =PosStart + 16; PosEnd = strHeadFind.find("\r\n", PosStart); std::string strLen =strHeadFind.substr(PosStart, PosEnd-PosStart); @@ -106,116 +106,6 @@ bool CWeatherDataSpider::CheckIfRecSucceed(char * buf, int nTotalRecv, int nFlag int iTotalRead = 0; inflate_read((char*)buf + PosStart, nlen, &Output, 1, iTotalRead); - - - // add by lei.zhao 2015-11-03, Bug[12533] - //bool bNewPacket = false; - //if (nFlag == WEATHER_FORECAST) - //{ - // char bufTemp[RECV_BUFF_LENGTH] = { 0 }; - // memcpy_s(bufTemp, RECV_BUFF_LENGTH, buf, nTotalRecv); - // bufTemp[nTotalRecv] = 0; - // - // CString strTemp; - // strTemp = bufTemp; - // strTemp = strTemp.MakeLower(); - // int nFindPos = strTemp.Find(L"content-length: "); - - // if (nFindPos != -1) - // { - // int nLengthStart = nFindPos + 16; - // int nLengthEnd = strTemp.Find(L"\r\n", nLengthStart); - // if (nLengthEnd == -1) - // { - // return false; - // } - // int nLength = _tstoi(strTemp.Mid(nLengthStart, nLengthEnd - nLengthStart)); - - // int nHearderLength = strTemp.Find(L"\r\n\r\n") + 4; - // if (nHearderLength == -1) - // { - // return false; - // } - // if (nHearderLength + nLength > nTotalRec) - // { - // return false; - // } - // memset(m_pbyXmlBuf, 0, 10000); - // char* Output = NULL;//= new char[10000]; - // int iTotalRead = 0; - // inflate_read((char*)buf + nHearderLength, nLength, &Output, 1, iTotalRead); - // memcpy_s(m_pbyXmlBuf, 10000, Output, iTotalRead); - // delete[]Output; - // bNewPacket = true; - // } - //} - //if (!bNewPacket) - //{ - // int nIndex = -1; - // for (int i = 0; i< nTotalRec; i++) - // { - // if (buf[i] == '\r' - // && buf[i + 1] == '\n' - // && buf[i + 2] == '\r' - // && buf[i + 3] == '\n' - // ) - // { - // nIndex = i + 4; - // break; - // } - // } - - // if (nIndex <0) - // { - // return false; - // } - - // memset(m_pbyXmlBuf, 0, 10000); - // if (nFlag == WEATHER_REALTIME) - // { - // memcpy_s(m_pbyXmlBuf, 10000, buf + nIndex, nTotalRec - nIndex); - // } - // else if (nFlag == WEATHER_FORECAST) - // { - // int nIndexR = nIndex; - // bool bFindCount = false; - // do - // { - // if (buf[nIndexR] == '\r' && buf[nIndexR + 1] == '\n') - // { - // bFindCount = true; - // break; - // } - // ++nIndexR; - // } while (nIndexR