Hello,
I've bought the SecureBridge so that I could use Https in my application.
I am having difficulties to rewrite a small code where I could use the secureBridge, I am not sure the steps and if the correct component would it be the ScHttpWebRequest, I appreciate a lot your help with my small code:
Retry:= True;
Tries := 0;
while Retry do
begin
HTTPSend.Clear;
PostStr := 'cnpj='+OnlyNumber(ACNPJ)+'&' +
'origem=comprovante&' +
'search_type=cnpj&' +
'submit1=Consultar&' +
'txtTexto_captcha_serpro_gov_br='+Trim(ACaptcha);
WriteStrToStream( HTTPSend.Document, PostStr );
HTTPSend.MimeType := 'application/x-www-form-urlencoded';
HTTPSend.Cookies.Add('flag=1');
HTTPSend.Headers.Add('Referer: https://www.receita.fazenda.gov.br/pess ... tacao3.asp');
HTTPPost('https://www.receita.fazenda.gov.br/pess ... valida.asp');
Retry := (Tries < 2) and
(pos('Captcha Sonoro', RespHTTP.Text) > 0) and
(pos(ACBrStr('Digite o número de CNPJ da empresa e clique em'), RespHTTP.Text) > 0);
Inc( Tries );
end;
regards
Alexandre
Rewrite the code to use the secureBridge
-
- Posts: 7
- Joined: Fri 15 Mar 2019 14:12
Re: Rewrite the code to use the secureBridge
You can try to use next code:
Code: Select all
var
Request: TScHttpWebRequest;
Response: TScHttpWebResponse;
Buf: TBytes;
PostStr, RespStr: string;
...
Request := TScHttpWebRequest.Create('https://www.receita.fazenda.gov.br/pessoajuridica/cnpj/cnpjreva/valida.asp');
Request.Referer := 'https://www.receita.fazenda.gov.br/pessoajuridica/cnpj/cnpjreva/Cnpjreva_solicitacao3.asp';
Request.Cookies.Add('flag=1');
Request.Method := rmPost;
PostStr := 'cnpj='+OnlyNumber(ACNPJ)+'&' +
'origem=comprovante&' +
'search_type=cnpj&' +
'submit1=Consultar&' +
'txtTexto_captcha_serpro_gov_br='+Trim(ACaptcha);
Buf := TEncoding.UTF8.GetBytes(PostStr);
try
Request.ContentType := 'application/x-www-form-urlencoded';
Request.ContentLength := Length(Buf);
Request.WriteBuffer(Buf);
Response := nil;
try
Response := Request.GetResponse;
RespStr := Response.ReadAsString;
finally
if Response <> nil then
Response.Free;
end;
finally
Request.Free;
end;
-
- Posts: 7
- Joined: Fri 15 Mar 2019 14:12
Re: Rewrite the code to use the secureBridge
Hello ViktorV,
First of all, I want to thank you for your help.
In your code there is function TEncoding.UTF8.GetBytes(PostStr) used,
where can I get this functin TEncoding.UTF8.GetBytes(PostStr) ? It seems there isn't it for delphi 2007.
regards
Alex
First of all, I want to thank you for your help.
In your code there is function TEncoding.UTF8.GetBytes(PostStr) used,
where can I get this functin TEncoding.UTF8.GetBytes(PostStr) ? It seems there isn't it for delphi 2007.
regards
Alex
Re: Rewrite the code to use the secureBridge
Please try ti use the next code for Dephi 2007:
Code: Select all
SetLength(Buf, Length(PostStr));
Move(PAnsiChar(PostStr)^, Pointer(Buf)^, Length(PostStr));