adsweb getting http 402 using TidHTTP - indy

I'm sometimes getting http 402 payment required when using TidHTTP accessing the Adsweb, but it is not on all computers. The same program run on one computer fine and on another I will get the 402 error running the same statement.
CSHttp: TidHTTP;
Try
CSHttp := TidHTTP.Create(nil);
MyURL := MasterTbl.FieldByName('DatabaseUrl').AsString;
MyUrl := MyUrl + '__query?statement=select%20name,accountnum%20from%20customer%20where%20accountnum=''' + Myphone + '''&$format=json'
with CSHttp do
begin
Request.CacheControl := 'no-cache';
Request.BasicAuthentication := True;
Request.Username := MasterTbl.FieldByName('DBlogin').AsString;
Request.Password := MasterTbl.FieldByName('DBPassword').AsString;
Request.UserAgent := 'Mozilla/3.0 (compatible; Indy Library)';
end;
Try
MyResult := CShttp.Get(MyURL);
Except
on E:Exception do
Myerror := E.Message;
End;
Finally
CSHttp.Free;
end;
If I restart the ADS 11 it will sometimes fix it.
Maybe it is something do wrong in the call?
Thanks,
Kim

Related

Indy IdHttp Digest Authentication - 401

When you try to take a picture from a camera, the authentication function does not work. I read all the other posts on the subject, but without success with this device.
Indy 10.6.2.0
Uses ..., IdAuthentication, IdAuthenticationDigest;
...
addr := 'cgi-bin/snapshot.cgi?1';
myADR := 'http://87.126.245.25:8181/' + addr;
rStream := TMemoryStream.Create;
try
H1 := TIdHttp.Create();
{$IFDEF DEBUG}
idLogFile := TIdLogFile.Create( H1 );
with idLogFile do begin
Filename := IncludeTrailingPathDelimiter( ExtractFileDir( Application.ExeName ) ) + 'indy_log.txt';
Active := true;
end;
{$ENDIF}
with H1 do begin
Response.KeepAlive := true;
ReadTimeout := selCAM.Timeout;
Request.BasicAuthentication := false;
Request.Username := selCAM.User;
Request.Password := selCAM.Pass;
Request.ContentType := 'image/jpeg';
Request.UserAgent := 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/97.0.4692.71';
Request.ContentVersion := '1.0';
Request.IPVersion := Id_IPv4;
Request.Host := 'http://' + addr;
HTTPOptions := [hoInProcessAuth, hoForceEncodeParams];
OnSelectAuthorization := IdHTTP_SelectAuthorization;
OnHeadersAvailable := IdHTTP_HeadersAvailable;
OnAuthorization := IdHTTP_Authorization;
{$IFDEF DEBUG} Intercept := idLogFile; {$ENDIF}
end;
try
H1.Get( myADR, rStream); except
on E: EIdHTTPProtocolException do begin SB1.Panels[0].Text := E.Message; er := true; end;
on E: EIdException do begin SB1.Panels[0].Text := E.Message; er := true; end;
on E: Exception do begin SB1.Panels[0].Text := E.Message; er := true; end;
end;
finally
H1.Free;
FreeAndNil(rStream);
end;
It works correctly through a browser
Attach wireshark from Browser, from Indy and Indy Log:
https://1drv.ms/u/s!AubiEh1vqvRLkr01GzXCf_T0yLgmfQ?e=69dqaD

Localized string values for the size strings KB, MB, GB etc.?

Where is this strins resources is stored on the Windows?
I need to show size corectly on native language of installed Windows.
Strings are very specific to the application that is using it. There are no generic string resouce in windows that an application can use. Of course you can write a program to search the resource in the windows folder to see which resource dll has the string that you are looking for and then use that resource dll in your application, but that is unadvisable. The reason being that, any new update of the windows that brings in resource dll changes can break your application.
As the other poster advises, you are better of writing your own resource dll and localize it in the languages that you want to support your application.
This is possible with disk quota library which is available since Windows XP:
function FindStringResourceEx(AInstance: HINST; AStringID: UINT; ALangID: UINT): PWideChar;
var
Res: HRSRC;
LoadedRes: HGLOBAL;
I: Integer;
begin
Result := nil;
Res := FindResourceEx(AInstance, RT_STRING, MAKEINTRESOURCE(AStringID div 16 + 1), ALangID);
if Res <> 0 then begin
LoadedRes := LoadResource(AInstance, Res);
if LoadedRes <> 0 then
try
Result := PChar(LockResource(LoadedRes));
if Assigned(Result) then
try
for I := 0 to (AStringID and 15) - 1 do
Inc(Result, PWord(Result)^ + 1);
finally
UnlockResource(THandle(Result));
end;
finally
FreeResource(LoadedRes);
end;
end;
end;
function GetSizeStrings(out sBytes, sKB, sMB, sGB, sTB, sPB, sEB: string): Boolean;
var
hLib: HMODULE;
sRes: string;
I: Integer;
SL: TStringList;
begin
Result := False;
hLib := LoadLibrary('dskquoui.dll');
if hLib > 0 then
try
SL := TStringList.Create;
try
sRes := FindStringResourceEx(hLib, 14472, MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL));
Result := sRes <> '';
if Result then begin
sRes := sRes.Remove(0, 1);
I := sRes.IndexOf(#$B);
if I > -1 then
sRes := sRes.Remove(I);
SL.Delimiter := #2;
SL.DelimitedText := sRes;
sBytes := SL[0]; // bytes
sKB := SL[1]; // KB
sMB := SL[2]; // MB
sGB := SL[3]; // GB
sTB := SL[4]; // TB
sPB := SL[5]; // PB
sEB := SL[6]; // EB
end;
finally
SL.Free;
end;
finally
FreeLibrary(hLib);
end;
if not Result then begin
sBytes := 'bytes';
sKB := 'KB';
sMB := 'MB';
sGB := 'GB';
sTB := 'TB';
sPB := 'PB';
sEB := 'EB';
end;
end;

RAD Studio 10.2 Indy doesn't send email using gmail

My problem is that when I use Indy to send email using Gmail it works ok in this computer where RAD Studio is installed. But when I copy my release version to different computer where is installed Windows 10 it gives an error "SSL negotiation failed"
My code is:
lIOHandler := TIdSSLIOHandlerSocketOpenSSL.Create(nil);
lIOHandler.SSLOptions.Method := sslvTLSv1;
lIOHandler.SSLOptions.Mode := sslmClient;
strA := EditOsoite.Text;
charArray[0] := ';';
o := 0;
IdSMTP1.IOHandler := lIOHandler;
IdSMTP1.UseTLS := utUseRequireTLS;
IdSMTP1.Host := 'smtp.gmail.com'; // EditPalvelin.Text;
//IdSMTP1.Authenticate;
// IdSMTP1.UseTLS := utUseExplicitTLS;
IdSMTP1.Username := EditPalvelin.Text;
IdSMTP1.Password := EditSalasana.Text;
IdSMTP1.Port := 587;
try
try
IdSMTP1.Connect;
IdSMTP1.Send(IdMessage1);
IdMessage1.Clear;
Sleep(1000);
//IdMessage1.Free;
except on E:Exception do begin
ShowMessage('Virhe lähetettäessä');
ShowMessage('There was an error: ' + E.Message);
//StatusMemo.Lines.Insert(0, 'ERROR: ' + E.Message) ;
end;
end;
finally
if IdSMTP1.Connected then begin
IdSMTP1.Disconnect;
//IdSMTP1.Free;
//IdMessage1.Free;
end;
end;

Log in twice via Idhttp

I have placed an Idhttp component on my main form and an IdSSLIOHandlerSocketOpenSSL and both components are not adjusted via the IDE. I use it to access two servers:
1) A http server which requires an authentication;
2) A https-server (which requires an authentication).
When I connect via Idhttp to server (1) I can connect via a regular fashion. However, when I connect to server (2) it returns a message that the user credentials are not correct.
I tried switching the procedures but then I cannot login into server (1): I get in both situations the response from the server that I input wrong credentials.
I presume some property is changed. I checked the Idhttp.Request.UserName and Idhttp.Request.Password before I connect and they are correct.
What is going wrong?
procedure TForm1.AccessServer1;
var
fs: TMemoryStream
begin
fs := TMemoryStream.Create;
IdHTTP1.Request.BasicAuthentication := true;
IdHTTP1.Request.UserName := myUsername1;
IdHTTP1.Request.Password := MyPassword1;
try
IdHTTP1.Get(myURL1, fs);
fs.SaveToFile(MyFilename);
finally
fs.free
end;
end;
procedure TForm1.AccessServer2;
var
fs: TMemoryStream
begin
fs := TMemoryStream.Create;
IdHTTP1.Request.BasicAuthentication := true;
IdHTTP1.Request.UserName := myUsername2;
IdHTTP1.Request.Password := MyPassword2;
IdHTTP1.HandleRedirects := True;
IdHTTP1.IOHandler := AIdSSLIOHandlerSocketOpenSSL;
try
IdHTTP1.Get(myURL2, fs);
fs.SaveToFile(MyFilename);
finally
fs.free
end;
end;

Copy Email Program to another computer

I wrote a program to send email in delphi xe3 , and it works fine , when I copy the program to another computer (windows 8) it works fine but on Computer (Windows 7) the stmp.send did not respond Unless I install embarcadero on it .I Think the problem is in the files libeay32.dll and ssleay32.dll
Here is the code
var
SMTP: TIdSMTP;
Email: TIdMessage;
SSLHandler: TIdSSLIOHandlerSocketOpenSSL;
begin
SMTP := TIdSMTP.Create(nil);
Email := TIdMessage.Create(nil);
SSLHandler := TIdSSLIOHandlerSocketOpenSSL.Create(nil);
try
SSLHandler.MaxLineAction := maException;
SSLHandler.SSLOptions.Method := sslvTLSv1;
SSLHandler.SSLOptions.Mode := sslmUnassigned;
SSLHandler.SSLOptions.VerifyMode := [];
SSLHandler.SSLOptions.VerifyDepth := 0;
SMTP.IOHandler := SSLHandler;
SMTP.Host := 'smtp.gmail.com';
SMTP.Username := 'Username#gmail.com';
SMTP.UseTLS := utUseExplicitTLS;
SMTP.Port := 587;
SMTP.Password := 'Password';
SMTP.Connect;
Email.Clear;
Email.AttachmentEncoding:='MIME' ;
Email.IsEncoded := true;
Email.Charset := 'utf-8';
Email.ContentType :='multipart/alternative';
Email.Encoding := meMime;
Email.UseNowForDate := true;
Email.From.Address := 'Address' ;
Email.Recipients.EmailAddresses := 'Recipients';
Email.Subject := 'Subject';
Email.Body.Text :='Body' ;
SMTP.Send(Email);
SMTP.Disconnect;
except on E:Exception do
Button1.Caption:=E.Message;
end;
SMTP.Free;
Email.Free;
SSLHandler.Free;
end;
Any idea Thanks
The files libeay32.dll and ssleay32.dll are needed by the executable. Place them in the same folder as the executable and it should work, even when you don't install Delphi on the target computer.

Resources