Jump to content

FloppyDesk

Members
  • Content Count

    6
  • Joined

  • Last visited

Community Reputation

0 Neutral
  1. FloppyDesk

    spinlock primitives

    David, can you please provide the code for AlignedOn32bitBoundary() func? Thanks.
  2. FloppyDesk

    Ics Multithreading exceptions

    I use tthread.synchronize method, to update my "memo" for logging. I need replace the synchronization method? What do you mean about message loop? I have "while" loop in main thread which loops until "tthread not terminated flag set". I use 10 threads and 10 instances of TSslHttpCli 10 threads = 10 instances, each instance works on their own thread. I use multiple threads for speed up the request sending and get result to the software. If you can, send please a demo or give me aiming on something what can help me. Thank you in advance Angus.
  3. Using 10 threads and after 100 iterations i got an exception. If i continue this exception, after 10 iterations it raises again, after VCL form frees and crashes. OnCreate Event Code: FHttpIcs := TSslHttpCli.Create(nil); FHttpIcs.MultiThreaded := True; FHttpIcs.SslContext := TSSLContext.Create(nil); FHttpIcs.ResponseNoException := True; FHttpIcs.FollowRelocation := True; FHttpIcs.LocationChangeMaxCount := 15; I tried to put FHttpIcs.SslContext := TSSLContext.Create(nil); in cycle (not onCreate event) but still no helps. Here is example of POST request, probably "same code" i have for GET requests. procedure TConnector.SubmitTokens; begin if (FThreadStatus = Terminated) then Exit; SetHeadersST(); SetPostParamsST(); FHttpIcs.RcvdStream := FResponseStream; FHttpIcs.Url := FUrl; try FHttpIcs.Post(); if (FHttpIcs.StatusCode > cBadRequest) or (FIsErrorConnection) then raise Exception.Create('err connection'); FHtmlResponse := FConnectorUtils.StreamToString(FResponseStream, TEncoding.UTF8); if (ContainsText(FHtmlResponse, 'true')) then // do some work else raise Exception.Create('err connection'); except on e: Exception do begin ReCheck(TMethods.SubmitTokensM); end; end; end;
  4. Thank you so much - Angus! Tried this property, all works! But this "OnRequestDone" event, i tried to write some code and i got stucked at one question. For example, we have error = 1 (which is bad connection) how i can reconnect same request with same headers/post parameters? I have much methods with requests, new headers, new post params, how i can handle this in this event? Thanks!
  5. Tried this code But problem not solved, same result in txt files in folder. Here is FConnectorUtils.StreamToStringCode: function TConnectorUtils.StreamToString(const Stream: TStream; const Encoding: TEncoding): string; var StringBytes: TBytes; begin Stream.Position := 0; SetLength(StringBytes, Stream.Size); Stream.ReadBuffer(StringBytes[0], Stream.Size); Result := Encoding.GetString(StringBytes); end; UPD!!!: PROBLEM SOLVED Problem was in EXCEPT BLOCK: I tried to parse html only on TRY block, but not in except. (Result Code of response is 400) One more question, can i disable this function like in indy? If responsecode > 400 then raise exception?
  6. Hello, i have a problem when i recieve response from only one response! I tried to analyze the request which i send from SOFT by "http analyzer/debugger" and analyzer shows me good !!!JSON!!! response which is: But, if i write "rcvdstream" to a file for see the result i got ANOTHER result which is not JSON! Here is my code: 1. Headers: procedure TConnector.SetHttpHeadersCFV; begin FHttpIcs.Agent := FUserAgent; FHttpIcs.ContentTypePost := cAppFormUrlEnc; FHttpIcs.Accept := ' application/json, text/javascript, */*; q=0.01'; FHttpIcs.AcceptLanguage := 'en-US;q=0.5,en;q=0.3'; FHeaders := ''; AddHeader('X-CORRELATION-ID: ' + FColeractionId); AddHeader('x-via-hint_dca: ' + '1_MTM0Mw=='); AddHeader('Origin: ' + 'https://cnn.com/'); AddHeader('Referer: ' + 'https://google.com'); AddHeader('X-THMID: ' + FXtmId); AddHeader('dfpSessionID: ' + FSessionId); AddHeader('X-Requested-With: ' + 'XMLHttpRequest'); AddHeader('Accept-Encoding: gzip, deflate'); FHttpIcs.ExtraHeaders.Text := FHeaders; end; Note: about encoding, i tried to delete accept-encoding header, no helps... 2. Sending request: // set post params // set headers // requesting.... FHttpIcs.RcvdStream := FResponseStream; // url .. https://..../ FHttpIcs.Url := Url; try FHttpIcs.Post(); if (FHttpIcs.StatusCode = cTooManyReqCode) then raise Exception.Create('err connection'); FHtmlResponse := FConnectorUtils.StreamToString(FResponseStream, TEncoding.Default); // !!!!! HTML RESPONSE IS INCORRECT !!!!! //// FConnectorUtils.LogToFile('htmlresponse_.txt', FHtmlResponse); // status code is correct! FConnectorUtils.LogToFile('statuscode_.txt', FHttpIcs.StatusCode.ToString); // phrase is correct! FConnectorUtils.LogToFile('phrase_.txt', FHttpIcs.ReasonPhrase); // last response is EMPTY!!!! FConnectorUtils.LogToFile('lastresponse_.txt', FHttpIcs.LastResponse); except // !!!!! HTML RESPONSE IS INCORRECT !!!!! //// FConnectorUtils.LogToFile('htmlresponse_.txt', FHtmlResponse); // status code is correct! FConnectorUtils.LogToFile('statuscode_.txt', FHttpIcs.StatusCode.ToString); // phrase is correct! FConnectorUtils.LogToFile('phrase_.txt', FHttpIcs.ReasonPhrase); // last response is EMPTY!!!! FConnectorUtils.LogToFile('lastresponse_.txt', FHttpIcs.LastResponse); ReCheck(TMethods.SendRequestM); end; Can someone help me please? thank you in advance!
×