I have faced a problem. I can't send parameters, when I post request with TScHttpWebRequest.
I have used a next code to send request:
Code: Select all
procedure TfMain.SBClick(Sender: TObject);
var
  Response: string;
  Stream: TStream;
  ScHttpWebRequest: TScHttpWebRequest;
  httpWebResponse: TScHttpWebResponse;
  ParamsLst: TStrings;
begin
  ScHttpWebRequest := TScHttpWebRequest.Create(nil);
  try
    ScHttpWebRequest.RequestUri := eURL.Text;
    Stream := TMemoryStream.Create;
    try
      ParamsLst := TStringList.Create;
      try
        ParamsLst.Add('F1_Submit');
        ParamsLst.SaveToStream(Stream);
        Stream.Position := 0;
        ScHttpWebRequest.Method := rmPost;
        ScHttpWebRequest.ContentLength := Stream.Size;
        ScHttpWebRequest.SendChunked := True;
        ScHttpWebRequest.RequestStream := Stream;
      finally
        ParamsLst.Free;
      end;
      httpWebResponse := ScHttpWebRequest.GetResponse();
      Response := httpWebResponse.ReadAsString;
      Memo1.Lines.Add(Response);
    finally
      Stream.Free;
    end;
  finally
    ScHttpWebRequest.Free;
  end;
end;
I have made a simple demo. I have sent a post request by two ways - using TScHttpWebRequest and using Indy.
Code: Select all
procedure TfMain.IndyClick(Sender: TObject);
var
  Http: TIdHTTP;
  Response: string;
  ParamsLst: TStrings;
  
begin
  Http := TIdHTTP.Create(nil);
  try
   ParamsLst:= TStringList.Create();
   try
     ParamsLst.Add('F1_Submit');
     Response := Http.Post(eURL.Text, ParamsLst);
    try
      if Response <> '' then
      begin
        Memo1.Lines.Add(Response);
      end;
    except
    end;
   finally
     ParamsLst.Free;
   end;
  finally
    FreeAndNil(http);
  end;
end;
Code: Select all
<?php
if (!empty($_POST))
{
    // Array of post values for each different form on your page.
    $postNameArr = array('F1_Submit', 'F2_Submit', 'F3_Submit');       
    // Find all of the post identifiers within $_POST
    $postIdentifierArr = array();
       
    foreach ($postNameArr as $postName)
    {
        if (array_key_exists($postName, $_POST))
        {
             $postIdentifierArr[] = $postName;
        }
    }
    // Only one form should be submitted at a time so we should have one
    // post identifier.  The die statements here are pretty harsh you may consider
    // a warning rather than this.
    if (count($postIdentifierArr) != 1)
    {
        count($postIdentifierArr) < 1 or
            die("\$_POST contained more than one post identifier: " .
               implode(" ", $postIdentifierArr));
        // We have not died yet so we must have less than one.
        die("\$_POST did not contain a known post identifier.");
    }
        
    switch ($postIdentifierArr[0])
    {
    case 'F1_Submit':
       echo "Perform actual code for F1_Submit.";
       break;
    case 'Modify':
       echo "Perform actual code for F2_Submit.";
       break;
          
    case 'Delete':
       echo "Perform actual code for F3_Submit.";
       break;
    }
}
else // $_POST is empty.
{
    echo "Perform code for page without POST data. ";
}
?>But I always get "Perform code for page without POST data. using TScHttpWebRequest. Would you help me resolve this problem.
Thank you