Ejemplo n.º 1
0
void TWebPgFetchEvent::OnConnect(const uint64& SockId){
  TChA RqChA;
  if (CurUrl->IsHttpRqStr()){
    RqChA=CurUrl->GetHttpRqStr();
  } else {
    // get http components
    TStr HostNm=CurUrl->GetHostNm();
    TStr AbsPath=CurUrl->GetPathStr()+CurUrl->GetSearchStr();
    // compose http request
    RqChA+="GET "; RqChA+=AbsPath; RqChA+=" HTTP/1.0\r\n";
    RqChA+="Host: "; RqChA+=HostNm; RqChA+="\r\n";
    if (!UserAgentStr.Empty()){ 
      RqChA+="User-Agent: "; RqChA+=UserAgentStr; RqChA+="\r\n";}
    // add cookies
    if (GetCookies()>0){
      RqChA+="Cookie: ";
      for (int CookieN=0; CookieN<GetCookies(); CookieN++){
        TStr KeyNm; TStr ValStr; TStr DmNm; TStr PathStr;
        GetCookie(CookieN, KeyNm, ValStr, DmNm, PathStr);
        if (HostNm.EndsWith(DmNm)){
          if (CookieN>0){RqChA+="; ";}
          RqChA+=KeyNm; RqChA+='='; RqChA+=ValStr; 
        }
      }
      RqChA+="\r\n";
    }
    // finish request
    RqChA+="\r\n";
  }
  // send http request
  PSIn RqSIn=TMIn::New(RqChA);
  bool Ok; TStr ErrMsg; Sock->Send(RqSIn, Ok, ErrMsg);
  if (Ok){
    Sock->PutTimeOut(TimeOutMSecs);
  } else {
    OnFetchError("Unable to send the data: " + ErrMsg);
  }
}