Jump to content

DarkDucke

Members
  • Content Count

    13
  • Joined

  • Last visited

Posts posted by DarkDucke


  1. 1 hour ago, Lars Fosdal said:

     

    Is it about the pitfalls of variable captures? The simplest solution to that is to simply divide and conquer.

    Also - the queuing code you wrote, will only do five scrapings since you never descrement nCount  when a task completes, nor do you retry the loop until there are no lines not containing 'done'.

    
    procedure TForm1.QueueScraping(I, Q: Integer);  
      Async(
        procedure
        begin
          Memo1.lines.add('I=' + I.ToString() + ' Q=' + Q.ToString());
          GetWebContent(I);
        end
      ).Await(
        procedure
        begin
           Memo1.lines.add('Done I=' + I.ToString() + ' Q=' + Q.ToString());
        end);
    end;
    
    procedure TForm1.BitBtn1Click(Sender: TObject);
    var
      I, nCount : Integer;
    begin
      I := 0;
      nCount := 0;
      for I := 1 to StringGrid.RowCount-1 
      do begin
        if StringGrid.Cells[0, I] <> 'done' 
        then begin
          inc(nCount);
          if nCount > 5 
           then Break;
          QueueScraping(I, nCount)
        end;
      end;
    end;

     

    In fact, I forgot to report, this code is in a button, but stored in a timer that checks again every 5s


  2. Hello, I need to create a task for each row of a TSgringGrid, this task will take content from a web page, and update the data in a cell.

    I tried as follows:

     

    procedure TForm1.BitBtn1Click(Sender: TObject);
    var
     I, nCount : Integer;
    begin
     I := 0;
     nCount := 0;
     
     for I := 1 to StringGrid.RowCount-1 do
       begin
    
        if StringGrid.Cells[0, I] <> 'done' then
          begin
    	    inc(Q);
    		if Q > 5 then
    		  Break;
    		
            Async(
             procedure
              begin
                 Memo1.lines.add('I=' + I.ToString() + ' Q=' + Q.ToString());
                 GetWebContent(I);
              end
            ).Await(
             procedure
              begin
                 Memo1.lines.add('Done I=' + I.ToString() + ' Q=' + Q.ToString());
              end);
    
          end;
      end;
    end;

     

    But that doesn't work, the value of I is always the same, I can't get the position of the TStringGrid line.

    How can I do this? Create 5 out of 5 tasks until all Grid lines have been queried.

     

    This cannot freeze the user interface.

     

    Thanks!!


  3. 20 hours ago, Angus Robertson said:

    O ICS contém dezenas de unidades, das quais apenas algumas são atualizadas para novos lançamentos. Muitas unidades têm versões mais antigas. Mas as unidades das quais dependem podem ser posteriores e corrigir erros nessa unidade. O zip noturno do SVN é o mais recente, o V8.63 será finalmente lançado ainda esta semana.

     

    Angus

     

    Thanks for the clarification, I will wait for the official release!


  4. On 11/12/2019 at 3:36 PM, Angus Robertson said:

    This was reported in this forum on 21st October and an illegal date of zero no longer raises an exception in V8.63 which will be released real soon, but can be downloaded now from SVN or the overnight zip. 

     

    But functionally your application will not behave differently, the conversion function simply returns zero rather the exception setting zero, so will not explain your other issues.  Are you using TSslHttpRest yet, it has cookie handling built-in.

     

    Angus

    Hello, could you give me the url to download the zip of version 8.63?
    I joined SVN a the version is still 8.62

     

    http://svn.overbyte.be:8443/svn/ics/trunk/Source/OverbyteIcsHttpProt.pas

    Version:      8.62

     

    Thanks!


  5. Hello guys, I am getting this error when doing a POST in a url.

    "404 Connection aborted on request"

     

      xUrlPost := 'https://urltopost.com/8/pay';
      Buf := AnsiString('{"value":90}');
      DataOut := TMemoryStream.Create;
      if Length(Buf) > 0 then      { Check if some data to post }
          DataOut.Write(Buf[1], Length(Buf));
      DataOut.Seek(0, soBeginning);
      HttpCli.RcvdHeader.NameValueSeparator := ':';
      HttpCli.ContentTypePost := 'application/json';
      HttpCli.SendStream      := DataOut;
      HttpCli.RcvdStream      := TMemoryStream.Create;
      HttpCli.URL :=  xUrlPost;
      HttpCli.PostASync;

    in event "RequestDone" StatusCode = 404 and ReasonPhrase = "Connection aborted on request"

    what does the message "Connection aborted on request"?

    How can I get more details to correct the error?

    I found this error message in unit "OverbyteIcsHttpProt" in procedure "THttpCli.Abort". but I don't use the "Abort" command at any time!

     

    procedure THttpCli.Abort;
    var
        bFlag : Boolean;
        Msg   : TMessage;
    begin
        FLocationFlag := FALSE;  { Do not follow relocations V7.10 }
        { The following two lines prevent OnRequestDone from trigger twice V7.10 }
        FRcvdCount    := 0;      { Clear the receive buffer V7.10 }
        FReceiveLen   := 0;      { Clear the receive buffer V7.10 }
    
        if FState = httpReady then begin
            FState := httpAborting;
            if FCtrlSocket.State <> wsClosed then
                FCtrlSocket.Abort;
            FStatusCode       := 200;
            FReasonPhrase     := 'OK';
            FRequestDoneError := httperrNoError;
            FState            := httpReady;
            TriggerStateChange;
            WMHttpRequestDone(Msg);   { Synchronous operation ! }
            Exit;
        end;
    
        bFlag := (FState = httpDnsLookup);
        StateChange(httpAborting);
    
        if bFlag then begin
            try
                FCtrlSocket.CancelDnsLookup;
            except
                { Ignore any exception }
            end;
        end;
    
        FStatusCode       := 404;
        FReasonPhrase     := 'Connection aborted on request';
        FRequestDoneError := httperrAborted;
    
        if bFlag then
            SocketSessionClosed(Self, 0)
        else
            FCtrlSocket.Close;
        StateChange(httpReady);  { 13/02/99 }
    end;

    I know error 404 as "page not found" but in this case the post url is correct. I copied the url from a post made from the browser!


  6. 2 hours ago, Angus Robertson said:

    This was reported in this forum on 21st October and an illegal date of zero no longer raises an exception in V8.63 which will be released real soon, but can be downloaded now from SVN or the overnight zip. 

     

    But functionally your application will not behave differently, the conversion function simply returns zero rather the exception setting zero, so will not explain your other issues.  Are you using TSslHttpRest yet, it has cookie handling built-in.

     

    Angus

    Thanks!


  7. I updated my version to "8.62", and when sending a POST to a url, an error occurs at this location:

    unit OverbyteIcsHttpProt;
    
    procedure THttpCli.GetHeaderLineNext;
    begin
    //...
            else if Field = 'expires' then begin     { V8.61 }
                try
                    FRespExpires := RFC1123_StrToDate(Data) ; //<===error
                except
                    FRespExpires := 0 ;
                end ;
    //...
    end;

    I can ignore the exception and receive the data, but cookies are not obtained, and to the browser by other pages, I get the error "403".

    Does anyone know about this error or how to troubleshoot?

     

    Thanks!


  8. 4 hours ago, Angus Robertson said:

    One possible reason is HTTP 1.0 does not support Keep-Alive, it should be 1.1.  You are also setting a POST content type but using GET.  That component added httpAuthBearer 18 months ago so you are probably using an old version. 

     

    You would be better using the newer TSslHttpRest component that is much easier to use than THttpCli and has a new demo OverbyteIcsHttpRestTst.dpr designed for OAuth2. REST and Json.

     

    Angus

     

    Hello, I updated the component to the latest version "8.62".
    I am using it as follows:

     

      HttpCliSusp.Connection      := 'Keep-Alive';
      HttpCliSusp.ContentTypePost := 'application/json;charset=UTF-8';
      HttpCliSusp.AuthBearerToken := mToken.Text;
      HttpCliSusp.RequestVer      := '1.1';
      HttpCliSusp.RcvdStream      := TMemoryStream.Create;
      HttpCliSusp.URL := 'url-to-get';
      HttpCliSusp.Get;

    And Now I get the error: Invalid argument to date encode.

     

    I'm not using the event "BeforeHeaderSend"


  9. Hello, I am trying to get data from a page and am getting error "206", the only detail is a "Authorization: Bearer" header.

    I'm entering the header in event "BeforeHeaderSend"

     

    Headers.Add('Authorization:Bearer ' + mToken.Text);
      HttpCliSusp.Connection      := 'Keep-Alive';
      HttpCliSusp.ContentTypePost := 'application/json;charset=UTF-8';
      HttpCliSusp.RequestVer      := '1.0';
      HttpCliSusp.RcvdStream      := TMemoryStream.Create;
      HttpCliSusp.URL := 'https://www.url-to-get.com';
      HttpCliSusp.Get;

    i get HttpCliSusp.StatusCode = 206

     

    Using the Indy component "TIdHttp" I get the content normally without error!

     

       IdHttp.Request.CustomHeaders.Add('Authorization:Bearer ' + mToken.Text);
       xHtmlRetorno := IdHttp.Get('https://www.url-get.com');

    xHtmlRetorno comes content without errors.

     

    Where am I going wrong using the ICS TSslHttpCli component?

     

    Thanks!!!

×