Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Delphi -> POST -> PHP

Posted on 2001-09-05
8
Medium Priority
?
1,731 Views
Last Modified: 2012-05-05
Hello,

I wrote an delphi application, that send via NMHTTP
data to the php-script (internet).

The PHP-Script should use this variables, for example
i send an string "test=abc"  the script should output
abc  ( echo $test)

But the variable is empty. When I send it via ?test=abc  the output is right. The POST via Delphi's NMHTTP don't work as I want ...

can anyone help me?

Thanx
Andy
0
Comment
Question by:andys79
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
8 Comments
 
LVL 8

Expert Comment

by:us111
ID: 6459809
first, in a simple HTML form, does the PHP post method work ??
I don't know NMHTTP, but I think it should work if NMHTTP support the post method
0
 

Author Comment

by:andys79
ID: 6460034
Hi,

for example to show my problem:

test1.html
-----------
<form name="test" method="POST" action="test2.php">
<input type="hidden" name="helloworld" value="yes">
<input type="submit">
</form>

test2.php
---------
<?php
echo "Skript running ...";
echo $helloworld;
// or: echo $HTTP_POST_VARS["helloworld"];
?>


=> OUTPUT: Skript running ...yes
-------------

the output is correct.
But when I use this script (test2.php) in Delphi via NMHTTP

     NMHTTP1.Post(Edit1.Text, 'helloword=yes');

then I get this:

=> OUTPUT: Skript running ...

(Edit1.Text is the URL of the php-internet-script)

I cannot access to the POST-Variable helloworld, or should I define the POST-Variables in another way in delphi?

Thanx

Andy

0
 
LVL 8

Expert Comment

by:us111
ID: 6460156
I believe that there's a problem with
NMHTTP1.Post(Edit1.Text, 'helloword=yes');

try
NMHTTP1.Get(Edit1.Text, 'helloword=yes');
if it exists :)

I don't know delphi
0
Find the IP of a Linux Server in Command Line

Knowing your server’s IP address(s) can be a useful bit of information to have for various reasons. This tutorial will teach you how to check the IPs of any modern Linux server. To follow along will simply need access to the server via SSH or TTY.

 

Author Comment

by:andys79
ID: 6463637
It doesn't work ...
(Too much parameter) ;-((
0
 
LVL 26

Accepted Solution

by:
EddieShipman earned 200 total points
ID: 6610916
Andy,
  I believe I saw your post on DelphiPages.com. I have been
taking a look at this and here's what I came up with.
Either you have to use GET with NMHTTP or Download Indy
and use Post... Here is an example program with NMHTTP
and Indy components showing how to do what you want...


unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Psock, NMHttp, StdCtrls, IdBaseComponent, IdComponent, IdTCPConnection,
  IdTCPClient, IdHTTP, idGlobal;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Edit1: TEdit;
    NMHTTP1: TNMHTTP;
    Label1: TLabel;
    Memo1: TMemo;
    IdHTTP1: TIdHTTP;
    Button2: TButton;
    Button3: TButton;
    Label2: TLabel;
    Memo2: TMemo;
    Memo3: TMemo;
    Button4: TButton;
    Memo4: TMemo;
    procedure Button1Click(Sender: TObject);
    procedure NMHTTP1Success(Cmd: CmdType);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure NMHTTP1AboutToSend(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
begin
  NMHTTP1.OutputFileMode := False;
  NMHTTP1.Get(Edit1.Text + '?helloworld=yes');
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  NMHTTP1.OutputFileMode := False;

  NMHTTP1.Post(Edit1.Text, '?helloworld=yes');
end;

procedure TForm1.NMHTTP1Success(Cmd: CmdType);
begin
  case Cmd of
  CmdPOST:
  begin
    Memo2.Text := NMHTTP1.Header;
    Label2.Caption := NMHTTP1.Body;
  end;
  CmdGET:
  begin
    Memo1.Text := NMHTTP1.Header;
    Label1.Caption := NMHTTP1.Body;
  end;
  end;
end;

procedure TForm1.Button2Click(Sender: TObject);
var
  mStream: TMemoryStream;
begin
  mStream := TMemoryStream.Create;
  IdHTTP1.Get(Edit1.Text + '?helloworld=yes', mStream);
  mStream.Position := 0;
  Memo3.Lines.LoadFromStream(mStream);
  mStream.Free;
end;

procedure TForm1.Button4Click(Sender: TObject);
var
  aStream: TMemoryStream;
  Params: TStringStream;
begin
  aStream := TMemoryStream.create;
  Params := TStringStream.create('');
  idHTTP1.Request.ContentType := 'application/x-www-form-urlencoded';
  try
    Params.WriteString(URLEncode('helloworld=' + 'yes'));
    with idHTTP1 do begin
      try
        Post(Edit1.Text, Params, aStream);
      except
        on E: Exception do
          showmessage('Error encountered during POST: ' + E.Message);
      end;
    end;
    aStream.Position := 0;
   Memo4.Lines.LoadFromStream(aStream);
  except
  end;
end;

procedure TForm1.NMHTTP1AboutToSend(Sender: TObject);
begin
  // I tried changing the content type here like in the Indy
  // component but still no go.
  NMHTTP1.SendHeader.Values['Content-Type'] := 'application/x-www-form-urlencoded';
end;

end.
0
 

Author Comment

by:andys79
ID: 6618935
Can a webserver accept posts from another application or is there a security mechanism?
0
 

Author Comment

by:andys79
ID: 6618936
Can a webserver accept posts from another application or is there a security mechanism?
Sorry, I was in holiday ..
0
 
LVL 26

Expert Comment

by:EddieShipman
ID: 6619014
Yes, as far as it's concerned, it is just another browser.

The example I show above works. I wrote a PHP program
just as you did and used the Delphi source above to
retrieve the value from the server.

0

Featured Post

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question