Return Type | Function name | Arguments |
---|---|---|
hzEcode | hzHttpClient::TestPage | (hzChain&,const hzUrl&,) |
Declared in file: hzHttpClient.h
Defined in file : hzHttpClient.cpp
Function Logic:
Function body:
hzEcode hzHttpClient::TestPage (hzChain& Z, const hzUrl& url) { _hzfunc("hzHttpClient::Testpage") ; chIter zi ; chIter hi ; chIter ti ; hzChain X ; hzCookie cookie ; hzString S ; hzString param ; hzString value ; hzString encoding ; uint32_t nRecv ; uint32_t nTry ; hzEcode rc = E_OK ; Z.Clear() ; m_Header.Clear() ; m_Content.Clear() ; if (!url.Domain()) { m_Error.Printf("TestPage: No host to locate\n") ; return E_ARGUMENT ; } /* ** ** Formulate HTTP request ** */ m_Request.Clear() ; if (url.Resource()) m_Request << "GET " << url.Resource() << " HTTP/1.1\r\n" ; else m_Request << "GET / HTTP/1.1\r\n" ; m_Request << "Accept: */*\r\nAccept-Language: en-gb\r\n" ; if (m_AuthBasic) m_Request << "Authorization: Basic " << m_AuthBasic << "\r\n" ; m_Request << "User-Agent: HadronZoo/0.8 Linux 2.6.18\r\n" ; m_Request << "Host: " << url.Domain() << "\r\n" ; if (m_Referer) m_Request << "Referer: " << m_Referer << "\r\n" ; m_Request << "Connection: Keep-Alive\r\n\r\n" ; /* ** ** Send request ** */ m_Error << " Sending [" << m_Request << "] to domain " << url.Domain() << "\n" ; rc = m_Webhost.Send(m_Request) ; if (rc != E_OK) { m_Error.Printf("Could not send request to domain [%s] (error=%s)\n", *url.Domain(), Err2Txt(rc)) ; return rc ; } for (nTry = 0; nTry < 4&& !m_Header.Size() ; nTry++) { rc = m_Webhost.Recv(m_buf, nRecv, HZ_MAXPACKET) ; if (rc != E_OK) { if (rc == E_NOSOCKET) m_Error.Printf("Connection closed by server\n") ; else m_Error.Printf("Could not recv bytes (nbytes=%d) from page %s (error=%s)\n", nRecv, *url.Resource(), Err2Txt(rc)) ; break ; } if (!nRecv) { m_Error.Printf("Got no response, retrying ...\n") ; sleep(1); continue ; } Z.Append(m_buf, nRecv) ; } if (rc != E_OK) { m_Error.Printf("Could not process response from [%s] (error=%s)\n", *url, Err2Txt(rc)) ; return rc ; } m_Referer = url ; return rc ; }