Indy IdHttp Digest Authentication - 401 - indy

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

Related

Why is my Delphi code not executing in order?

I am creating a program, and I need to display an image and then block input for a few seconds before allowing it again. The problem I am running into is that Delphi is not running the code in order and is executing the Sleep() command before the image command. I have run into this problem before when using Sleep() with a video before displaying a message.
The code looks as follows:
procedure TtForm.WindowsMediaPlayer2Click(ASender: TObject;
nButton, nShiftState: SmallInt; fX, fY: Integer);
Var
buttonSelected: Integer;
begin
buttonSelected := MessageDlg('Well done Monkey!-_-', mtError, mbOKCancel, 0);
if buttonSelected = mrOK then
begin
Pages.Visible := False;
WindowsMediaPlayer2.Visible := False;
imgEroor.BringToFront;
BorderStyle := bsNone;
WindowState := wsMaximized;
imgEroor.Top := 0;
imgEroor.Left := 0;
imgEroor.Width := Screen.Width;
imgEroor.Height := Screen.Height;
imgEroor.BringToFront;
BlockInput(True);
Sleep(10000);
BlockInput(False);
end;
if buttonSelected = mrCancel then
begin
Pages.Visible := False;
WindowsMediaPlayer2.Visible := False;
imgEroor.BringToFront;
BorderStyle := bsNone;
WindowState := wsMaximized;
imgEroor.Top := 0;
imgEroor.Left := 0;
imgEroor.Width := Screen.Width;
imgEroor.Height := Screen.Height;
imgEroor.BringToFront;
BlockInput(True);
Sleep(10000);
BlockInput(False);
end;
end;

Colours of controls on custom wizard page are not correct on Windows 7 - Parallels (Inno Script)

Context:
MacBook Pro (latest Big Sur 11.1)
Parallels (latest)
Windows 7 (all updates)
When I run my setup, my custom page looks like this:
Some text is showing black. This issue does not happen when you run my installer on native Windows 10 on a PC.
My custom page is designed like this:
// ================================================
// Automatic Backup Settings Page
// ================================================
[Code]
{ Constants }
const
BackupWhat_None = 0;
BackupWhat_Complete = 1;
BackupWhat_Essential = 2;
BackupMode_Automatic = 0;
BackupMode_Manual = 1;
BackupPrompt_Never = 0;
BackupPrompt_Daily = 1;
BackupPrompt_Weekly = 2;
BackupPrompt_Monthly = 3;
{ Global Variables }
var
pageAutoBackup: TWizardPage;
pnlBackupWhat: TPanel;
lblBackupWhat: TLabel;
radBackupWhatNone: TNewRadioButton;
radBackupWhatComplete: TNewRadioButton;
radBackupWhatEssential: TNewRadioButton;
lblBackupMode: TLabel;
pnlBackupMode: TPanel;
radBackupModeAuto: TNewRadioButton;
radBackupModeManual: TNewRadioButton;
lblPromptMode: TLabel;
cmbPromptMode: TNewComboBox;
lblBackupFolder: TLabel;
txtBackupFolder: TNewEdit;
btnSelectBackupFolder: TNewButton;
{ Sets the state of the controls }
procedure EnableAutoBackupSettingPageControls();
var
bEnable: Boolean;
begin
bEnable := radBackupWhatComplete.Checked or radBackupWhatEssential.Checked
pnlBackupMode.Enabled := bEnable;
lblBackupMode.Enabled := bEnable;
radBackupModeAuto.Enabled := bEnable;
radBackupModeManual.Enabled := bEnable;
lblPromptMode.Enabled := bEnable;
cmbPromptMode.Enabled := bEnable;
lblBackupFolder.Enabled := bEnable;
txtBackupFolder.Enabled := bEnable;
btnSelectBackupFolder.Enabled := bEnable;
if(radBackupWhatNone.Checked = True) then
Wizardform.NextButton.Enabled := True
else
Wizardform.NextButton.Enabled := DirExists(txtBackupFolder.Text);
WizardForm.Update;
end;
{ Ask user to select the backup Folder location }
procedure btnSelectBackupFolder_Click(Sender: TObject);
var
strFolder: string;
begin
strFolder := txtBackupFolder.Text;
{ Display Browse Window }
if(BrowseForFolder('', strFolder, True)) then
begin
txtBackupFolder.Text := strFolder;
Wizardform.NextButton.Enabled := DirExists(txtBackupFolder.Text);
WizardForm.Update;
end;
end;
{ Action handler }
procedure radBackupWhat_Click(Sender: TObject);
begin
{ Set control states }
EnableAutoBackupSettingPageControls();
end;
{ Automatic Backup Settings Custom Page }
function pageAutoBackup_CreatePage(PreviousPageId: Integer): Integer;
var
iButtonGap: Integer;
begin
{ Create the page }
pageAutoBackup := CreateCustomPage(PreviousPageId,
ExpandConstant('{cm:pageAutoBackupTitle}'),
ExpandConstant('{cm:pageAutoBackupDescription}'));
{ pnlBackupWhat (TPanel) }
pnlBackupWhat := TPanel.Create(pageAutoBackup);
pnlBackupWhat.Caption := '';
pnlBackupWhat.BevelOuter := bvNone;
pnlBackupWhat.BevelInner := bvNone; { default }
pnlBackupWhat.BevelKind := bkNone;
pnlBackupWhat.Parent := pageAutoBackup.Surface;
pnlBackupWhat.Enabled := True;
pnlBackupWhat.Visible := True;
pnlBackupWhat.Left := ScaleX(0);
pnlBackupWhat.Top := ScaleY(0);
pnlBackupWhat.Width := pageAutoBackup.Surface.Width;
pnlBackupWhat.Anchors := [akLeft, akRight];
{ lblBackupWhat (TLabel) }
lblBackupWhat := TLabel.Create(pageAutoBackup);
lblBackupWhat.Parent := pnlBackupWhat;
lblBackupWhat.Enabled := True;
lblBackupWhat.Visible := True;
lblBackupWhat.Width := pnlBackupWhat.Width;
lblBackupWhat.Caption := ExpandConstant('{cm:lblBackupWhat}');
{ radBackupWhatNone (TNewRadioButton) }
radBackupWhatNone := TNewRadioButton.Create(pageAutoBackup);
radBackupWhatNone.Parent := pnlBackupWhat;
radBackupWhatNone.Enabled := True;
radBackupWhatNone.Visible := True;
radBackupWhatNone.Top := lblBackupWhat.Top + lblBackupWhat.Height + ScaleY(2);
radBackupWhatNone.Width := pnlBackupWhat.Width;
radBackupWhatNone.Height := ScaleY(radBackupWhatNone.Height);
radBackupWhatNone.Checked := False;
radBackupWhatNone.Caption := ExpandConstant('{cm:radBackupWhatNone}');
radBackupWhatNone.OnClick := #radBackupWhat_Click;
{ radBackupWhatComplete (TNewRadioButton) }
radBackupWhatComplete := TNewRadioButton.Create(pageAutoBackup);
radBackupWhatComplete.Parent := pnlBackupWhat;
radBackupWhatComplete.Enabled := True;
radBackupWhatComplete.Visible := True;
radBackupWhatComplete.Top := radBackupWhatNone.Top + radBackupWhatNone.Height + ScaleY(2);
radBackupWhatComplete.Width := pnlBackupWhat.Width;
radBackupWhatComplete.Height := ScaleY(radBackupWhatComplete.Height);
radBackupWhatComplete.Checked := False;
radBackupWhatComplete.Caption := ExpandConstant('{cm:radBackupWhatComplete}');
radBackupWhatComplete.OnClick := #radBackupWhat_Click;
{ radBackupWhatEssential (TNewRadioButton) }
radBackupWhatEssential := TNewRadioButton.Create(pageAutoBackup);
radBackupWhatEssential.Parent := pnlBackupWhat;
radBackupWhatEssential.Enabled := True;
radBackupWhatEssential.Visible := True;
radBackupWhatEssential.Top := radBackupWhatComplete.Top + radBackupWhatComplete.Height + ScaleY(2);
radBackupWhatEssential.Width := pnlBackupWhat.Width;
radBackupWhatEssential.Height := ScaleY(radBackupWhatEssential.Height);
radBackupWhatEssential.Checked := False;
radBackupWhatEssential.Caption := ExpandConstant('{cm:radBackupWhatEssential}');
radBackupWhatEssential.OnClick := #radBackupWhat_Click;
{ Now we can set the panel height! }
pnlBackupWhat.ClientHeight :=
radBackupWhatEssential.Top + radBackupWhatEssential.Height + ScaleY(5);
{ pnlBackupMode (TPanel) }
pnlBackupMode := TPanel.Create(pageAutoBackup);
pnlBackupMode.Caption := '';
pnlBackupMode.BevelOuter := bvNone;
pnlBackupMode.BevelInner := bvNone; { default }
pnlBackupMode.BevelKind := bkNone;
pnlBackupMode.Parent := pageAutoBackup.Surface;
pnlBackupMode.Enabled := True;
pnlBackupMode.Visible := True;
pnlBackupMode.Top := pnlBackupWhat.Top + pnlBackupWhat.Height + ScaleY(2);
pnlBackupMode.Width := pageAutoBackup.Surface.Width;
pnlBackupMode.Height := ScaleY(100);
pnlBackupMode.Anchors := [akLeft, akRight];
{ lblBackupMode (TLabel) }
lblBackupMode := TLabel.Create(pageAutoBackup);
lblBackupMode.Parent := pnlBackupMode;
lblBackupMode.Enabled := True;
lblBackupMode.Visible := True;
lblBackupMode.Width := pnlBackupMode.Width;
lblBackupMode.Caption := ExpandConstant('{cm:lblBackupMode}');
{ radBackupModeAuto (TNewRadioButton) }
radBackupModeAuto := TNewRadioButton.Create(pageAutoBackup);
radBackupModeAuto.Parent := pnlBackupMode;
radBackupModeAuto.Enabled := True;
radBackupModeAuto.Visible := True;
radBackupModeAuto.Left := ScaleX(0);
radBackupModeAuto.Top := lblBackupMode.Top + lblBackupMode.Height + ScaleY(2);
radBackupModeAuto.Width := pnlBackupMode.Width;
radBackupModeAuto.Height := ScaleY(radBackupModeAuto.Height);
radBackupModeAuto.Checked := False;
radBackupModeAuto.Caption := ExpandConstant('{cm:radBackupModeAuto}');
{ radBackupModeManual (TNewRadioButton) }
radBackupModeManual := TNewRadioButton.Create(pageAutoBackup);
radBackupModeManual.Parent := pnlBackupMode;
radBackupModeManual.Enabled := True;
radBackupModeManual.Visible := True;
radBackupModeManual.Top := radBackupModeAuto.Top + radBackupModeAuto.Height + ScaleY(2);
radBackupModeManual.Width := pnlBackupMode.Width;
radBackupModeManual.Height := ScaleY(radBackupModeManual.Height);
radBackupModeManual.Checked := False;
radBackupModeManual.Caption := ExpandConstant('{cm:radBackupModeManual}');
{ lblPromptMode (TLabel) }
lblPromptMode := TLabel.Create(pageAutoBackup);
lblPromptMode.Parent := pnlBackupMode;
lblPromptMode.Enabled := True;
lblPromptMode.Visible := True;
lblPromptMode.Top := radBackupModeManual.Top + radBackupModeManual.Height + ScaleY(10);
lblPromptMode.Width := pnlBackupMode.Width;
lblPromptMode.Caption := ExpandConstant('{cm:lblPromptMode}');
{ cmbPromptMode (TNewComboBox) }
cmbPromptMode := TNewComboBox.Create(pageAutoBackup);
cmbPromptMode.Parent := pnlBackupMode;
cmbPromptMode.Style := csDropDownList;
cmbPromptMode.Enabled := True;
cmbPromptMode.Visible := True;
cmbPromptMode.Top := lblPromptMode.Top + lblPromptMode.Height + ScaleY(5);
cmbPromptMode.Width := pnlBackupMode.Width;
cmbPromptMode.ItemIndex := 0;
cmbPromptMode.Items.Add(ExpandConstant('{cm:cmbPromptModeItemNever}'));
cmbPromptMode.Items.Add(ExpandConstant('{cm:cmbPromptModeItemDaily}'));
cmbPromptMode.Items.Add(ExpandConstant('{cm:cmbPromptModeItemWeekly}'));
cmbPromptMode.Items.Add(ExpandConstant('{cm:cmbPromptModeItemMonthly}'));
cmbPromptMode.Anchors := [akLeft, akRight];
{ Now we can set the panel height! }
pnlBackupMode.ClientHeight :=
(cmbPromptMode.Top + cmbPromptMode.Height) + ScaleY(5);
{ lblBackupFolder (TLabel) }
lblBackupFolder := TLabel.Create(pageAutoBackup);
lblBackupFolder.Parent := pageAutoBackup.Surface;
lblBackupFolder.Enabled := True;
lblBackupFolder.Visible := True;
lblBackupFolder.Top := pnlBackupMode.Top + pnlBackupMode.Height + ScaleY(2);
lblBackupFolder.Width := pnlBackupMode.Width;
lblBackupFolder.Caption := ExpandConstant('{cm:lblBackupFolder}');
lblBackupFolder.Anchors := [akLeft, akRight, akBottom];
{ txtBackupFolder (TNewEdit) }
txtBackupFolder := TNewEdit.Create(pageAutoBackup);
txtBackupFolder.Parent := pageAutoBackup.Surface;
txtBackupFolder.Enabled := True;
txtBackupFolder.ReadOnly := True;
txtBackupFolder.Visible := True;
txtBackupFolder.Top := lblBackupFolder.Top + lblBackupFolder.Height + ScaleY(5);
txtBackupFolder.Anchors := [akLeft, akRight, akBottom];
{ btnSelectBackupFolder (TNewButton) }
btnSelectBackupFolder := TNewButton.Create(pageAutoBackup);
btnSelectBackupFolder.Parent := pageAutoBackup.Surface;
btnSelectBackupFolder.Enabled := True;
btnSelectBackupFolder.Visible := True;
btnSelectBackupFolder.Left := pageAutoBackup.Surface.Width - WizardForm.CancelButton.Width;
btnSelectBackupFolder.Top := txtBackupFolder.Top;
btnSelectBackupFolder.Width := WizardForm.CancelButton.Width;
btnSelectBackupFolder.Height := WizardForm.CancelButton.Height;
btnSelectBackupFolder.Caption := SetupMessage(msgButtonBrowse);
btnSelectBackupFolder.Anchors := [akRight, akBottom];
btnSelectBackupFolder.OnClick := #btnSelectBackupFolder_Click;
{ Now we can set the text box width!
Use the gap between the Next and Cancel buttons for consistency.}
iButtonGap := WizardForm.CancelButton.Left -
(WizardForm.NextButton.Left + WizardForm.NextButton.Width);
txtBackupFolder.Width :=
pageAutoBackup.Surface.Width - btnSelectBackupFolder.Width - iButtonGap;
Result := pageAutoBackup.ID;
end;
function GetWhatToBackupMode(Param: string): string;
begin
if(radBackupWhatComplete.Checked) then
begin
Log('What to backup: Complete backup mode selected.');
Result := IntToStr(BackupWhat_Complete);
end
else if(radBackupWhatEssential.Checked) then
begin
Log('What to backup: Essential backup mode selected.');
Result := IntToStr(BackupWhat_Essential);
end
else begin
Log('What to backup: No backup mode selected.');
Result := IntToStr(BackupWhat_None);
end;
end;
function GetHowToBackupMode (Param: string): string;
begin
if(radBackupModeManual.Checked) then
begin
Log('How to backup: Perform the backup manually.');
Result := IntToStr(BackupMode_Manual);
end
else begin
Log('How to backup: Perform the backup automatically.');
Result := IntToStr(BackupMode_Automatic);
end;
end;
function GetBackupPromptMode (Param: string): string;
begin
Log('Where to backup: ' + cmbPromptMode.Items[cmbPromptMode.ItemIndex]);
Result := IntToStr(cmbPromptMode.ItemIndex);
end;
function GetBackupLocationPath (Param: string): string;
begin
// If empty, use the app folder and create a backup folder (Param)
Log(txtBackupFolder.Text);
Result := txtBackupFolder.Text;
end;
procedure AutoBackupPage_InitializeWizard(AfterId: Integer);
var
dwBackupAtShutdownWhat: Cardinal;
dwBackupAtShutdownHow: Cardinal;
dwBackupPromptMode: Cardinal;
strBackupFolder: String;
begin
pageAutoBackup_CreatePage(AfterId);
{ What to Backup }
dwBackupAtShutdownWhat := BackupWhat_None;
if (IsWin64) then
begin
RegQueryDWordValue(HKLM64,
'Software\MeetSchedAssist\Meeting Schedule Assistant\Options',
'BackupAtShutdownWhat', dwBackupAtShutdownWhat)
end else
begin
RegQueryDWordValue(HKLM,
'Software\MeetSchedAssist\Meeting Schedule Assistant\Options',
'BackupAtShutdownWhat', dwBackupAtShutdownWhat);
end;
if (dwBackupAtShutdownWhat = BackupWhat_Complete) then
begin
radBackupWhatComplete.Checked := True;
end
else if (dwBackupAtShutdownWhat = BackupWhat_Essential) then
begin
radBackupWhatEssential.Checked := True;
end
else begin
radBackupWhatNone.Checked := True;
end;
{ How to Backup }
dwBackupAtShutdownHow := BackupMode_Automatic;
if (IsWin64) then
begin
RegQueryDWordValue(HKLM64,
'Software\MeetSchedAssist\Meeting Schedule Assistant\Options',
'BackupAtShutdownMode', dwBackupAtShutdownHow);
end else
begin
RegQueryDWordValue(HKLM,
'Software\MeetSchedAssist\Meeting Schedule Assistant\Options',
'BackupAtShutdownMode', dwBackupAtShutdownHow);
end;
if (dwBackupAtShutdownHow = BackupMode_Manual) then
begin
radBackupModeManual.Checked := True;
end
else begin
radBackupModeAuto.Checked := True;
end;
{ Backup Prompt Mode }
dwBackupPromptMode := BackupPrompt_Never;
if (IsWin64) then
begin
RegQueryDWordValue(HKLM64,
'Software\MeetSchedAssist\Meeting Schedule Assistant\Options',
'BackupPromptMode', dwBackupPromptMode);
end else
begin
RegQueryDWordValue(HKLM,
'Software\MeetSchedAssist\Meeting Schedule Assistant\Options',
'BackupPromptMode', dwBackupPromptMode);
end;
cmbPromptMode.ItemIndex := dwBackupPromptMode;
{ Backup Local Path }
strBackupFolder := '';
if (IsWin64) then
begin
RegQueryStringValue(HKLM64,
'Software\MeetSchedAssist\Meeting Schedule Assistant\Options',
'BackupAtShutdownLocalPath', strBackupFolder);
end else
begin
RegQueryStringValue(HKLM,
'Software\MeetSchedAssist\Meeting Schedule Assistant\Options',
'BackupAtShutdownLocalPath', strBackupFolder);
end;
{ Do we need to reset the existing folder? }
if(not DirExists(strBackupFolder)) then strBackupFolder := '';
txtBackupFolder.Text := strBackupFolder;
end;
procedure AutoBackupPage_CurPageChanged(CurPageID: Integer);
begin
if CurPageID = pageAutoBackup.ID then
begin
{ Get the state of the Next button correct }
if(radBackupWhatNone.Checked) then
Wizardform.NextButton.Enabled := True
else
Wizardform.NextButton.Enabled := DirExists(txtBackupFolder.Text);
WizardForm.Update;
end;
end;
{ Build the Memo text for the Auto Backup Settings page }
function AutoBackupPage_MemoInfo(Space, NewLine: String): String;
begin
Result := Result + ExpandConstant('{cm:pageAutoBackupTitle}') + NewLine;
{ What to Backup }
Result := Result + Space + ExpandConstant('{cm:lblBackupWhat}') + NewLine;
if(radBackupWhatNone.Checked) then
Result := Result + Space + Space + ExpandConstant('{cm:radBackupWhatNone}') + NewLine;
if(radBackupWhatComplete.Checked) then
Result := Result + Space + Space + ExpandConstant('{cm:radBackupWhatComplete}') + NewLine;
if(radBackupWhatEssential.Checked) then
Result := Result + Space + Space + ExpandConstant('{cm:radBackupWhatEssential}') + NewLine;
if(radBackupWhatNone.Checked = False) then
begin
{ How to Backup }
Result := Result + Space + ExpandConstant('{cm:lblBackupMode}') + NewLine;
if(radBackupModeAuto.Checked) then
Result := Result + Space + Space + ExpandConstant('{cm:radBackupModeAuto}') + NewLine;
if(radBackupModeManual.Checked) then
Result := Result + Space + Space + ExpandConstant('{cm:radBackupModeManual}') + NewLine;
{ Prompt Mode }
Result := Result + Space + Space + ExpandConstant('{cm:lblPromptMode}') + NewLine;
if(cmbPromptMode.ItemIndex = BackupPrompt_Never) then
Result := Result + Space + Space + Space + ExpandConstant('{cm:cmbPromptModeItemNever}') + NewLine;
if(cmbPromptMode.ItemIndex = BackupPrompt_Daily) then
Result := Result + Space + Space + Space + ExpandConstant('{cm:cmbPromptModeItemDaily}') + NewLine;
if(cmbPromptMode.ItemIndex = BackupPrompt_Weekly) then
Result := Result + Space + Space + Space + ExpandConstant('{cm:cmbPromptModeItemWeekly}') + NewLine;
if(cmbPromptMode.ItemIndex = BackupPrompt_Monthly) then
Result := Result + Space + Space + Space + ExpandConstant('{cm:cmbPromptModeItemMonthly}') + NewLine;
{ Backup Folder }
Result := Result + Space + ExpandConstant('{cm:lblBackupFolder}') + NewLine;
Result := Result + Space + Space + txtBackupFolder.Text + NewLine;
end;
Result := Result + NewLine;
end;
I am using skinning as you can see (#define Skin "Amakrits.vsf").
I didn't anticipate this rendering issue.
Works fine for me on latest Win 10.
Your picture shows you have selected "Don't perform..." option which disables the controls in next group, that is a reason why the controls have different colors.
Did you make any changes in the skin file Amakrits.vsf? My skin looks different (I downloaded it from GitHub few moments ago) and it looks like some tweaks are missing in my case.
Conclusion: this is not an Inno Setup issue, but problem in VCL skinning plugin (try to post your issue here: https://github.com/RRUZ/vcl-styles-plugins/issues), but it looks like it can be improved by tweaking the colors in used .vsf file.
P.S. your script could not be compiled correctly as there were missing Custom Messages and skin / setup initialization functions.

How to post binary jpg file using Indy10 Http?

I have to post a jpg file using TIdHTTP component (Indy 10). What I need is to upload a file to a Drupal 8 field. I can do it with Advanced Rest Client following this documentation:
https://www.drupal.org/docs/8/core/modules/jsonapi-module/file-uploads
https://www.drupal.org/node/3024331#comment-13387295
But I'm tring to do it with Delphi 2010 and Indy 10 without success. I always get a "415 Unsupported media type" error with this detail:
"No route found that matches "Content-Type: multipart/form-data".
This is the code I use:
var
response: string;
Params: TIdMultiPartFormDataStream;
begin
Result := '';
IdHTTP1.ConnectTimeout := 10000;
IdHTTP1.Request.Clear;
IdHTTP1.Request.CustomHeaders.Clear;
IdHTTP1.Request.BasicAuthentication := false;
IdHTTP1.Request.ContentType := 'application/octet-stream';
IdHTTP1.Request.Accept := 'application/vnd.api+json';
IdHTTP1.Request.ContentLanguage := 'es';
IdHTTP1.Request.CustomHeaders.AddValue('api-key', 'my_api_key_here');
IdHTTP1.Request.ContentDisposition:= 'file; filename="testimage.jpg"';
IdHTTP1.Request.Charset := 'utf-8';
IdHTTP1.AllowCookies := True;
IdHTTP1.Request.UserAgent := 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.115 Safari/537.36';
IdHTTP1.HandleRedirects := True;
Params := TIdMultiPartFormDataStream.Create;
try
try
Params.AddFile('testimage.jpg','c:\tmp\testimage.jpg','application/octet-stream').ContentTransfer:='binary';
response:= IdHTTP1.Post('<my_url_to_the_field_as_instructions>', Params);
except
on E: Exception do
begin
memo1.Lines.add('Error ' + E.message);
end;
end;
finally
Params.Free;
end;
You can't post the file using TIdMultiPartFormDataStream, because the server is explicitly telling you that it does not support multipart/form-data requests (calling TIdHTTP.Post() with a TIdMultiPartFormDataStream overwrites the Request.ContentType).
You will have to post the file use a plain vanilla TStream instead, such as TFileStream:
var
response: string;
PostData: TStream;
begin
Result := '';
IdHTTP1.ConnectTimeout := 10000;
IdHTTP1.Request.Clear;
IdHTTP1.Request.BasicAuthentication := false;
IdHTTP1.Request.ContentType := 'application/octet-stream';
IdHTTP1.Request.Accept := 'application/vnd.api+json';
IdHTTP1.Request.ContentLanguage := 'es';
IdHTTP1.Request.CustomHeaders.AddValue('api-key', 'my_api_key_here');
IdHTTP1.Request.ContentDisposition := 'file; filename="testimage.jpg"';
IdHTTP1.AllowCookies := True;
IdHTTP1.Request.UserAgent := 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.115 Safari/537.36';
IdHTTP1.HandleRedirects := True;
PostData := TFileStream.Create('<path_to>\testimage.jpg', fmOpenRead or fmShareDenyWrite);
try
try
response := IdHTTP1.Post('<my_url_to_the_field_as_instructions>', PostData);
except
on E: Exception do
begin
Memo1.Lines.Add('Error ' + E.message);
end;
end;
finally
PostData.Free;
end;
end;
Alternatively, TIdHTTP has an overload of Post() that takes a file path as input:
var
response: string;
begin
Result := '';
IdHTTP1.ConnectTimeout := 10000;
IdHTTP1.Request.Clear;
IdHTTP1.Request.BasicAuthentication := false;
IdHTTP1.Request.ContentType := 'application/octet-stream';
IdHTTP1.Request.Accept := 'application/vnd.api+json';
IdHTTP1.Request.ContentLanguage := 'es';
IdHTTP1.Request.CustomHeaders.AddValue('api-key', 'my_api_key_here');
IdHTTP1.Request.ContentDisposition := 'file; filename="testimage.jpg"';
IdHTTP1.AllowCookies := True;
IdHTTP1.Request.UserAgent := 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.115 Safari/537.36';
IdHTTP1.HandleRedirects := True;
try
response := IdHTTP1.Post('<my_url_to_the_field_as_instructions>', '<path_to>\testimage.jpg');
except
on E: Exception do
begin
Memo1.Lines.Add('Error ' + E.message);
end;
end;
end;

Inno Setup - How to change a label caption [or other controls in general], when selected value in combox box changes

When changing a language in combo box (without clicking ok), I want to change texts of the dialog (label, form caption, button caption)
procedure SelectLanguage();
var
LanguageForm: TSetupForm;
CancelButton: TNewButton;
OKButton: TNewButton;
LangCombo: TNewComboBox;
SelectLabel: TNewStaticText;
Languages: TStrings;
Params: string;
Instance: THandle;
P, I: Integer;
S, L: string;
begin
Languages := TStringList.Create();
Languages.Add('en=English');
Languages.Add('cs='+#$010C+'e'+#$0161+'tina');
LanguageForm := CreateCustomForm;
LanguageForm.Caption := SetupMessage(msgSelectLanguageTitle);
LanguageForm.ClientWidth := ScaleX(297);
LanguageForm.ClientHeight := ScaleY(125);
LanguageForm.BorderStyle := bsDialog;
LanguageForm.Center;
CancelButton := TNewButton.Create(LanguageForm);
CancelButton.Parent := LanguageForm;
CancelButton.Left := ScaleX(214);
CancelButton.Top := ScaleY(93);
CancelButton.Width := ScaleY(75);
CancelButton.Height := ScaleY(23);
CancelButton.TabOrder := 3;
CancelButton.ModalResult := mrCancel;
CancelButton.Caption := SetupMessage(msgButtonCancel);
OKButton := TNewButton.Create(LanguageForm);
OKButton.Parent := LanguageForm;
OKButton.Left := ScaleX(133);
OKButton.Top := ScaleY(93);
OKButton.Width := ScaleX(75);
OKButton.Height := ScaleY(23);
OKButton.Caption := SetupMessage(msgButtonOK);
OKButton.Default := True
OKButton.ModalResult := mrOK;
OKButton.TabOrder := 2;
LangCombo := TNewComboBox.Create(LanguageForm);
LangCombo.Parent := LanguageForm;
LangCombo.Left := ScaleX(16);
LangCombo.Top := ScaleY(56);
LangCombo.Width := ScaleX(273);
LangCombo.Height := ScaleY(21);
LangCombo.Style := csDropDownList;
LangCombo.DropDownCount := 16;
LangCombo.TabOrder := 1;
SelectLabel := TNewStaticText.Create(LanguageForm);
SelectLabel.Parent := LanguageForm;
SelectLabel.Left := ScaleX(16);
SelectLabel.Top := ScaleY(8);
SelectLabel.Width := ScaleX(273);
SelectLabel.Height := ScaleY(39);
SelectLabel.AutoSize := False
SelectLabel.Caption := SetupMessage(msgSelectLanguageLabel);
SelectLabel.TabOrder := 0;
SelectLabel.WordWrap := True;
for I := 0 to Languages.Count - 1 do
begin
P := Pos('=', Languages.Strings[I]);
L := Copy(Languages.Strings[I], 0, P - 1);
S := Copy(Languages.Strings[I], P + 1, Length(Languages.Strings[I]) - P);
LangCombo.Items.Add(S);
if L = ActiveLanguage then
LangCombo.ItemIndex := I;
end;
if LanguageForm.ShowModal = mrOK then
begin
{ ... }
end;
end;
function InitializeSetup(): Boolean;
begin
SelectLanguage();
{ ... }
end;
Spanish: first language.
I select English and no change the language of the language selector.
You have the code already. You just need to make some local variables in the SelectLanguage function global, so they can be used in the LangChange function:
var
LanguageForm: TSetupForm;
SelectLabel: TNewStaticText;
CancelButton: TNewButton;
procedure LangChange(Sender : TObject);
begin
case TNewComboBox(Sender).ItemIndex of
0: { English }
begin
SelectLabel.Caption := 'Select the language to use during the installation:';
CancelButton.Caption := 'Cancel';
LanguageForm.Caption := 'Select setup language';
end;
1: { Czech }
begin
SelectLabel.Caption := 'Zvolte jazyk, kter'+#$FD+' se m'+#$E1+' pou'+#$17E+#$ED+'t b'+#$11B+'hem instalace:';
CancelButton.Caption := 'Storno';
LanguageForm.Caption := 'V'+#$FD+'b'+#$11B+'r jazyka pr'+#$16F+'vodce instalac'+#$ED+'';
end;
end;
end;
In the SelectLanguage, remove these the declarations of local variables:
LanguageForm: TSetupForm;
SelectLabel: TNewStaticText;
CancelButton: TNewButton;
And assign the LangChange event handler:
LangCombo.OnChange := #LangChange;

Windows firewall rule for XP

How to programmatically add an application or port to Windows Firewall on Windows XP?
Try this code extracted from our open source SQlite3UI.pas unit:
function GetXPFirewall(var fwMgr, profile: OleVariant): boolean;
begin
Result := (Win32Platform=VER_PLATFORM_WIN32_NT) and
(Win32MajorVersion>5) or ((Win32MajorVersion=5) and (Win32MinorVersion>0));
if result then // need Windows XP at least
try
fwMgr := CreateOleObject('HNetCfg.FwMgr');
profile := fwMgr.LocalPolicy.CurrentProfile;
except
on E: Exception do
result := false;
end;
end;
const
NET_FW_PROFILE_DOMAIN = 0;
NET_FW_PROFILE_STANDARD = 1;
NET_FW_IP_VERSION_ANY = 2;
NET_FW_IP_PROTOCOL_UDP = 17;
NET_FW_IP_PROTOCOL_TCP = 6;
NET_FW_SCOPE_ALL = 0;
NET_FW_SCOPE_LOCAL_SUBNET = 1;
procedure AddApplicationToXPFirewall(const EntryName, ApplicationPathAndExe: string);
var fwMgr, profile, app: OleVariant;
begin
if GetXPFirewall(fwMgr,profile) then
try
if profile.FirewallEnabled then begin
app := CreateOLEObject('HNetCfg.FwAuthorizedApplication');
try
app.ProcessImageFileName := ApplicationPathAndExe;
app.Name := EntryName;
app.Scope := NET_FW_SCOPE_ALL;
app.IpVersion := NET_FW_IP_VERSION_ANY;
app.Enabled :=true;
profile.AuthorizedApplications.Add(app);
finally
app := varNull;
end;
end;
finally
profile := varNull;
fwMgr := varNull;
end;
end;
procedure AddPortToXPFirewall(const EntryName: string; PortNumber: cardinal);
var fwMgr, profile, port: OleVariant;
begin
if GetXPFirewall(fwMgr,profile) then
try
if profile.FirewallEnabled then begin
port := CreateOLEObject('HNetCfg.FWOpenPort');
port.Name := EntryName;
port.Protocol := NET_FW_IP_PROTOCOL_TCP;
port.Port := PortNumber;
port.Scope := NET_FW_SCOPE_ALL;
port.Enabled := true;
profile.GloballyOpenPorts.Add(port);
end;
finally
port := varNull;
profile := varNull;
fwMgr := varNull;
end;
end;
It will allow you to add an application or a port to the XP firewall.
Should work from Delphi 6 up to XE.
Scripting the Windows Firewall is possible, see Scripting the Windows Firewall
And code examples for example here

Resources