2
Good morning to all,
I wonder if anyone could help me in the following situation:
I am 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 Importer WSDL, I did not build XML in "nail", let’s say so.
I was able to perform the authentication in the beforePost event as an example below:
auth := 'Authorization: Basic ' + EncodeString('login:senha');
HttpAddRequestHeaders(Data, PChar(auth), Length(auth), HTTP_ADDREQ_FLAG_ADD);
the problem is the following, the first time I run the application and consume the web service, works perfectly, makes the authentication and gives me a return, everything ok.
However, without closing the application if performing another query, returns the authentication error (WS Authentication Error).
If you close the application and open again the first query works.
Could someone help?
Following is the source of 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;
Grateful from now on.
Hello everyone, one more piece of information: I used a third component in which the Httprio component was changed, when performing some tests with this component I disabled an option called "Allowcookies", after disabling this option worked perfectly. I came to the conclusion then that the problem is with the storage of cookies in the navigation. The problem now is how to clear cookies, and the native HTTPRIO component does not have this property (Allowcookies); Any suggestions? Thank you!
– João Paulo Muller
where does Httpaddrequestheaders come from? and HTTP_ADDREQ_FLAG_ADD
– Ben-hur Hungaro
Both come from the windows API. Uses: Winapi.Wininet
– João Paulo Muller