How to prevent dialogue (basic authentication) during a Webservice call

In a delphi program (running as a service) I need to call some web services.
Calls work fine if basic authentication is not required. Calls also work just fine if basic authentication is required, as well as a username / password (in BeforePost) using:

InternetSetOption(Data, INTERNET_OPTION_USERNAME,... InternetSetOption(Data, INTERNET_OPTION_PASSWORD,... 

But if basic authentication is requested, and the username / password is not provided, the program calls the af prompt for the username / password (i.e. NO-GO in the servlet).

So, how can I signal that I DO NOT want an invitation, but instead an error?

The problem is that, how can I use it, in the SOAPHTTPTrans function THTTPReqResp.Send (const ASrc: TStream): Integer; (line 762 (second call to InternetErrorDlg by this method)).

EDIT1:
if I change the flags at the beginning of the submit method (in SOAPHTTPTRANS) to include INTERNET_FLAG_NO_AUTH, it works the way I wanted.
But how can I do this without changing SAOPHTTPTrans (if possible)?

EDIT2:

 ws := THTTPRIO.Create(Self); ws.URL := 'http://excample.com/ws.asmx'; ws.HTTPWebNode.InvokeOptions := [soIgnoreInvalidCerts]; ws.HTTPWebNode.OnBeforePost := WebServiceCallBeforePost; AvailabilityWebservice := (ws as AvailabilityServiceSoap); sTemp := AvailabilityWebservice.GetVersion; 

Where AvailabilityServiceSoap is the interface generated using the WSDL importer.

+6
source share
3 answers

You can create a new class that inherits from THTTPReqResp and overrides the submit method so that you can include your own flags. You must install ws.HTTPWebNode on the new node using the new class.

Something like

 ws := THTTPRIO.Create(Self); MyNewNode := MyNewClass.Create; ws.HTTPWebNode := MyNewNode; ws.URL := 'http://excample.com/ws.asmx'; ws.HTTPWebNode.InvokeOptions := [soIgnoreInvalidCerts]; ws.HTTPWebNode.OnBeforePost := WebServiceCallBeforePost; AvailabilityWebservice := (ws as AvailabilityServiceSoap); sTemp := AvailabilityWebservice.GetVersion; 
+1
source

I had this problem when trying Windows Live Messenger to work through a web filter.

As a result, I wrote a small program that automatically authenticates.

Hope this helps too.

 uses ... IdHTTP ...; ... var httpGetter: TIdHTTP; ... httpGetter.Request.Username := username; httpGetter.Request.Password := password; httpGetter.HandleRedirects := True; httpGetter.Request.BasicAuthentication := True; //custom useragent required to let live messenger work //this part is probably not necessary for your situation httpGetter.Request.UserAgent := 'MSN Explorer/9.0 (MSN 8.0; TmstmpExt)'; httpGetter.Get(url,MS); ... 
+2
source

How to check server authentication mode first?

http://en.wikipedia.org/wiki/Basic_access_authentication

  • The client requests a page that requires authentication, but do not provide a username and password. This usually happens because the user simply type in the address or after the link to the page.
  • The server responds with 401 response codes and provides authentication.

Thus, the client application can send Get and see if the response has a header, for example

 WW-Authenticate: Basic realm="Secure Area" 
+1
source

All Articles