Good morning everyone ,
I wonder if anyone could help me in the following situation:
I'm doing an integration with the SPC / CDL web service, which requires a basic authentication (HTTP header).
I need to do this authentication using HTTRIO because I used the WSDL Importer, I did not build the XML on the nail, so to speak.
I was able to authenticate to the beforePost event as shown below:
auth := 'Authorization: Basic ' + EncodeString('login:senha');
HttpAddRequestHeaders(Data, PChar(auth), Length(auth), HTTP_ADDREQ_FLAG_ADD);
The problem is this, the first time I run the application and consume the web service, it works perfectly, it does the authentication and it gives me a return, everything ok.
However, without closing the application if you make one more query, it returns the authentication error (WS Authentication Error).
If you close the application and open the first query again, it works.
Could anyone help?
Here is the source for a project I did here for testing:
procedure TForm3.BitBtn1Click(Sender: TObject);
var C:ConsultaSpcScWSService;
F:filtroConsultaSpcPlusMasterProtestoSCWS2;
R:RespostaConsultaSpcPlusMasterProtestoSC2;
H:THTTPRIO;
begin
H := THTTPRIO.Create(self);
H.HTTPWebNode.OnBeforePost := HTTPRIO1HTTPWebNode1BeforePost;
try
C := GetConsultaSpcScWSService(false,'',H);
F := filtroConsultaSpcPlusMasterProtestoSCWS2.Create;
try
F.cpfCnpj := 'xxxx';
R := C.SPCPlusMasterProtestoSC_65(f);
Memo1.Text := R.consumidor.nome;
R.free;
finally
C := nil;
F.free;
end;
except on E:exception do
Memo1.Text := 'Erro :'+E.Message;
end;
end;
procedure TForm3.HTTPRIO1HTTPWebNode1BeforePost(
const HTTPReqResp: THTTPReqResp; Data: Pointer);
var auth:string;
begin
auth := 'Authorization: Basic ' + EncodeString('user:pass');
HttpAddRequestHeaders(Data, PChar(auth), Length(auth), HTTP_ADDREQ_FLAG_ADD);
end;
Thank you in advance.