Jump to content

Pascal script that updates web-server for mobile app?

snoopunit

I want to send information from a Pascal script running on my PC to a webserver that can be accessed from a mobile application (android in my case). I'm pretty much clueless on where to start with this. I've read some interesting things abut push notifications via Discord webhooks or even an app called Pushover, but i'm looking for a bit more functionality than just push notifications. I wan't to build a custom include for myself where I can send update information and view the current status of my script in real time on my phone.

 

Could anyone help me find a starting point?   

Link to comment
Share on other sites

Link to post
Share on other sites

Depends on your environment, mostly.

 

On Delphi, try Indy.

On Free Pascal, try Synapse (if you have a GUI) or the built-in fphttp (if you don't).

Write in C.

Link to comment
Share on other sites

Link to post
Share on other sites

On 8/2/2019 at 5:26 AM, Dat Guy said:

Depends on your environment, mostly.

 

On Delphi, try Indy.

On Free Pascal, try Synapse (if you have a GUI) or the built-in fphttp (if you don't).

Thanks for the help! It looks like fphttp is exactly what I want. 

 

https://wiki.freepascal.org/fphttpclient

 

so basically what i'm understanding is I install OpenSSL libraries and it will allow me to upload text file to HTTP server using POST?

 

now I just need to figure out how to make HTTP server  

Link to comment
Share on other sites

Link to post
Share on other sites

Here's the code from that topic:

 

uses zipper, fphttpclient;
 
function TForm1.IsOpenSSLAvailable: Boolean;
const
  {$IFDEF WIN64}
    cOpenSSLURL = 'http://packages.lazarus-ide.org/openssl-1.0.2j-x64_86-win64.zip';
  {$ENDIF}
  {$IFDEF WIN32}
    cOpenSSLURL = 'http://packages.lazarus-ide.org/openssl-1.0.2j-i386-win32.zip';
  {$ENDIF}
var
  {$IFDEF MSWINDOWS}
  UnZipper: TUnZipper;
  FHTTPClient: TFPHTTPClient;
  ParamPath, LibeayDLL, SsleayDLL, ZipFile: String;
  {$EndIf}
begin
  {$IFDEF MSWINDOWS}
  ParamPath := ExtractFilePath(ParamStr(0));
  LibeayDLL := ParamPath + 'libeay32.dll';
  SsleayDLL := ParamPath + 'ssleay32.dll';
  Result := FileExists(Libeaydll) and FileExists(Ssleaydll);
  if not Result then
  begin
    ZipFile := ParamPath + ExtractFileName(cOpenSSLURL);
    FHTTPClient := TFPHTTPClient.Create(nil);
    try
      try
        FHTTPClient.Get(cOpenSSLURL, ZipFile);
       except
       end;
    finally
      FHTTPClient.Free;
    end;
    if FileExists(ZipFile) then
    begin
      UnZipper := TUnZipper.Create;
      try
        try
          UnZipper.FileName := ZipFile;
          UnZipper.Examine;
          UnZipper.UnZipAllFiles;
        except
        end;
      finally
        UnZipper.Free;
      end;
      DeleteFile(ZipFile);
      Result := FileExists(Libeaydll) and FileExists(Ssleaydll);
    end;
  end;
  {$ELSE}
  FOpenSSLAvailable := True;
  {$ENDIF}
end;
 
procedure TForm1.FormCreate(Sender: TObject);
begin
  if not IsOpenSSLAvailable then
    MessageDlg('OpenSSL dll''s are not available', mtInformation, [mbOk], 0);
end;
 

I have modified it to take a ZIP file URL from a website instead of the hard-coded one in this example, but it is working really well.

Write in C.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×