Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 3 of 3 total
Thread Request problem
Wed, Mar 20 2013 3:20 PMPermanent Link

Uli Becker

I am trying to send a POST request to a php script:

  with GetRequest do
  begin
    URL := 'android_testpost.php';
    GetRequest.params.clear;
    GetRequest.Params.Add('spieltag=30');
    Execute;
  end;

  with PostRequest do
  begin
    method = rmPost;
    URL := 'android_testpost.php';
    PostRequest.params.clear;
    PostRequest.Params.Add('ligaid=test1');
    RequestHeaders.Values['Content-Type'] := 'plain/text';

RequestHeaders.Values['Content-Length']:=IntToStr(Length(RequestContent.Text));
    Execute;
  end;

Whatever I tried: the script was able to read the GET-variable that I
sent with a GET-request, but not the POST-variable sent with a POST-request.

I wrote this simple php-code just to test that:

     if (count($_GET) > 0) {
       echo "Get-Variable found";
     } else  {
        echo "No Get-Variable found";
    }
    if (count($_POST) > 0) {
      echo "Post-Variable found";
    } else  {
      echo "No Post-Variable found";
    }

Funny: When I send a POST-request, the script tells me "Get-Variable
found", but it NEVER says "Post-Variable found".

Am I doing something wrong?

Uli
Wed, Mar 20 2013 4:32 PMPermanent Link

Peter

when you set the RequestContent instead of setting the Params

RequestContent.Clear();
RequestContent.Add('ligaid=test1');

... you can get the postdata with:

$postdata = file_get_contents("php://input");

Greetings ... Peter
---
Sorry for my weird english
Thu, Mar 21 2013 3:22 AMPermanent Link

Uli Becker

Peter,

thanks. Since I have never used a post request, I didn't realize that params are always get variables.

Sorry about the silly question.

Regards Uli
Image