Recent

Author Topic: [Help] Rest API programming.  (Read 27961 times)

shonay

  • Full Member
  • ***
  • Posts: 169
Re: [Help] Rest API programming.
« Reply #30 on: November 13, 2015, 09:10:51 pm »
Seems you dont get this same issues , which version of Lazarus are u using Sir, hence I think i have to switch
I use Lazarus development version (trunk) and Lazarus 1.4.4 for testing.

Lazarus 1.4.4 (the latest downloadable stable version) will work fine for you.

Downloading that right away Sir. Lemme test and get back to you
When the power of love overcomes the love of power, the world would know Peace

- Jimi Hendrix.

shonay

  • Full Member
  • ***
  • Posts: 169
Re: [Help] Rest API programming.
« Reply #31 on: November 14, 2015, 07:24:19 am »
@rvk

Ok hello and good morning

I have downloaded the Lazarus -1.4.4 and when i tried to compile the program, it compiled successfully and except that it threw back a warning about Editboxes which am working on atm.
Now passing the parameters , You spoke about using & in the passing of the parameters . How are they done via POST in this example cos thats what i seem to be worried about as it also gives me problems here

i am following this URL http://stackoverflow.com/questions/11471513/how-to-send-a-file-and-other-post-data-with-synapse and it seems to be tard harder than i expected.
When the power of love overcomes the love of power, the world would know Peace

- Jimi Hendrix.

rvk

  • Hero Member
  • *****
  • Posts: 6989
Re: [Help] Rest API programming.
« Reply #32 on: November 14, 2015, 09:00:49 am »
I'm not sure why you're following that example to send a file.

If you say you have problems with passing the data like data1=2&data2=2 etc you should explain what troubles exactly. We can't help you if you don't explain your troubles.

But why don't you take my EXACT code and try to make that work first. The only thing you need to do is set a few editboxes (I used tlabeledits) and name them like I did, put a tmemo named memoresult on the form and a button named btverify. Put my code in the onclick of the button and it should work. Don't forget to put the openssl dlls (2 of them) in your project directory.

At what point do you run into trouble and what exactly is the trouble. Always describe it as detailed as possible so if you get errors, copy the errors here and show us your code. That's the only way we can help you.

shonay

  • Full Member
  • ***
  • Posts: 169
Re: [Help] Rest API programming.
« Reply #33 on: November 15, 2015, 07:49:25 pm »
Good evening RVK, sorry I haven't been on, I been taking sometime to study further before I come back here to talk again :D
Suppose I want to send a post request to say

http://Http://localhost/info/information.php
And parameter is

"Firstname=darwin&email=darwin@xvvs.net&phone=1423652340"

How do you do this using synapse?
When the power of love overcomes the love of power, the world would know Peace

- Jimi Hendrix.

rvk

  • Hero Member
  • *****
  • Posts: 6989
Re: [Help] Rest API programming.
« Reply #34 on: November 15, 2015, 08:12:15 pm »
You would do it like this:
(I would have thought my previous example was clear enough)

Code: Pascal  [Select][+][-]
  1. uses httpsend; // the function HttpPostURL is in there
  2.  
  3. procedure SendMyDate;
  4. var
  5.   UrlData: string;
  6.   Url: string;
  7.   Data: TMemoryStream;
  8. begin
  9.   UrlData := 'Firstname=darwin&email=darwin@xvvs.net&phone=1423652340';
  10.   Url := 'http://http//localhost/info/information.php';
  11.   Data := TMemoryStream.Create;
  12.   try
  13.     if HttpPostURL(Url, UrlData, Data) then
  14.     begin
  15.       // The Data TStream contains any info given back by the site
  16.       // Data.Position := 0;
  17.       // memoResult.Lines.LoadFromStream(Data);
  18.     end;
  19.   finally
  20.     Data.Free;
  21.   end;
  22. end;

Although that wouldn't work because you have an error in your url.
It probably should be:
Code: Pascal  [Select][+][-]
  1.   Url := 'http://localhost/info/information.php';

shonay

  • Full Member
  • ***
  • Posts: 169
Re: [Help] Rest API programming.
« Reply #35 on: November 15, 2015, 08:36:31 pm »
@rvk, many thanks sir!

In that case what I did was correct! Just wanted to be sure.
And sorry I typed that url from my mobile. Have so fallen in love with lazarus that I have it on both on PC and phone :D

Thanks again. Let me work on something and get back to you sir.

Most grateful again for your time
When the power of love overcomes the love of power, the world would know Peace

- Jimi Hendrix.

shonay

  • Full Member
  • ***
  • Posts: 169
Re: [Help] Rest API programming.
« Reply #36 on: November 16, 2015, 07:16:12 am »

Morning RVK and everyone.
Many thanks again. Here is one if the questions I want to ask and I think I should call it a day from there.
Now I have mastered that tut for console now let's say I want to have it in GUI where I would have text boxes, buttons and the likes. Now I want the user to enter say email from a textbox.
Now here is what I did, don't know if I did it correctly. Just want to be very sure.
code looks like this:

Code: [Select]
program sendinfos

uses httpsend,windows,winsock;

UrlData: string;
 Url: string;
 Email : string;
Data: TMemoryStream;

begin
Email := email.text;
 UrlData := 'Firstname=darwin&email=+ Email +&phone=1423652340';
Url := 'http://localhost/infos/information.php';
Data := TMemoryStream.Create;

HttpPostURL(Url, UrlData, Data) ;
showmessage('Success');

end.
When the power of love overcomes the love of power, the world would know Peace

- Jimi Hendrix.

rvk

  • Hero Member
  • *****
  • Posts: 6989
Re: [Help] Rest API programming.
« Reply #37 on: November 16, 2015, 08:16:30 am »
Now here is what I did, don't know if I did it correctly. Just want to be very sure.
shonay, this is the second or third time you ask this without actually testing your bit of code yourself.

Using the code in console or GUI doesn't make much of a difference for the code.

But, no, your code is not correct.
I see 3 apparent errors: 
  • Put a Showmessage(UrlData) after the UrlData := line and see what you're doing wrong there.
  • Furthermore... you Create a TMemoryStream and don't free it afterwards.
  • And last... you give a message 'Success' without actually checking if HttpPostURL succeeded.
I think you need to go and try running these code-snippets yourself because it's clear that you didn't do that here. You say you wanted to test this in a GUI but you created a console application (see your program). You have a Email string but trying to read Email.text. You would have seen your code doesn't run AT ALL. So next time you ask a question, please, try your code first out yourself and fix the most apparent errors. Just asking theoretical if the you typed is correct, without trying to run it, won't help you in the long run.

shonay

  • Full Member
  • ***
  • Posts: 169
Re: [Help] Rest API programming.
« Reply #38 on: November 17, 2015, 06:36:31 am »
@rvk,,

Ok now today , i tried it again as you asked me to do so and i have been able to debug some errors i earlier got, It was fun tho, but it all came to this finally

i got this error

Code: [Select]
pmmystorepage.pas(8,79) Fatal: Cannot find unit httpsend used by pmmystorepage. Check if package laz_synapse is in the dependencies of the Project Inspector.

It all appears to be there , i added the package via package --> Add lazarus package.lpk

but here is what my source code looks like , i even went as far as adding the .lpk and ssl_openssl.pas together with the project.

Code: Pascal  [Select][+][-]
  1. unit pmmystorepage;
  2.  
  3. {$mode delphi}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls , httpsend, ssl_openssl;
  9.  
  10. type
  11.  
  12.   { TForm1 }
  13.  
  14.   TForm1 = class(TForm)
  15.     Button1: TButton;
  16.     Button2: TButton;
  17.     Edit1: TEdit;
  18.     Edit2: TEdit;
  19.     Edit3: TEdit;
  20.     Edit4: TEdit;
  21.     Label1: TLabel;
  22.     Label2: TLabel;
  23.     Label3: TLabel;
  24.     Label4: TLabel;
  25.     procedure Button1Click(Sender: TObject);
  26.   private
  27.     { private declarations }
  28.   public
  29.     { public declarations }
  30.   end;
  31.  
  32. var
  33.   Form1: TForm1;
  34.  
  35. implementation
  36.  
  37. {$R *.lfm}
  38.  
  39. { TForm1 }
  40.  
  41. procedure TForm1.Button1Click(Sender: TObject);
  42. HTTP: THTTPSend;
  43.  Url: string;
  44.  UrlData: string;
  45.  Data: TMemoryStream;
  46.  
  47. begin
  48.       UrlData := 'login'=+Edit1.text+'&PAYEE_ACCOUNT='+Edit2.text+'&PAYMENT_UNITS='+Edit3.text+'&PAYMENT_AMOUNT='+Edit4.text+;
  49.  
  50.       Url := 'https://perfectmoney.is/acct/confirm.asp';
  51.       Data := TMemoryStream.Create;
  52.       try
  53.         if HttpPostURL(Url, UrlData, Data) then
  54.         begin
  55.            showMessage('Payment Confirmed');
  56.           end;
  57.         finally
  58.           Data.Free;
  59.  
  60. end;
  61.  
  62. end.
  63.  
  64.  
« Last Edit: November 17, 2015, 06:59:30 am by shonay »
When the power of love overcomes the love of power, the world would know Peace

- Jimi Hendrix.

rvk

  • Hero Member
  • *****
  • Posts: 6989
Re: [Help] Rest API programming.
« Reply #39 on: November 17, 2015, 09:48:26 am »
It all appears to be there , i added the package via package --> Add lazarus package.lpk
Just adding a lazarus package to Lazarus doesn't add it to a project.
If you want to use a lazarus project you should add it as a requirement in the Project inspector > Add > New requirement

But perhaps it's easier to include the path to Synapse in Project > Project options > Compiler options > Path > Other unit files.
That works for me.

(You're still trying to do the post to confirm.asp. I recommend first using verify.asp in your test-phase so you don't actually send funds to that other account. verify.asp works exactly as confirm.asp but won't actually send funds. It just checks the validity of your query. After you receive a successful answer you can do it again to confirm.asp.)

shonay

  • Full Member
  • ***
  • Posts: 169
Re: [Help] Rest API programming.
« Reply #40 on: November 17, 2015, 10:28:04 am »
It all appears to be there , i added the package via package --> Add lazarus package.lpk


Just adding a lazarus package to Lazarus doesn't add it to a project.
If you want to use a lazarus project you should add it as a requirement in the Project inspector > Add > New requirement

But perhaps it's easier to include the path to Synapse in Project > Project options > Compiler options > Path > Other unit files.
That works for me.

(You're still trying to do the post to confirm.asp. I recommend first using verify.asp in your test-phase so you don't actually send funds to that other account. verify.asp works exactly as confirm.asp but won't actually send funds. It just checks the validity of your query. After you receive a successful answer you can do it again to confirm.asp.)

This evening. I show you what I have
When the power of love overcomes the love of power, the world would know Peace

- Jimi Hendrix.

 

TinyPortal © 2005-2018