0

I can't get my server app to properly receive anything.

Sender code using a design-time TIdHTTP component, with property
Request.Accept = text/html, */*

procedure TFrmTTWebserviceTester.Button1Click(Sender: TObject);
var
   lJSO : ISuperObject;
   lRequest: TStringStream;
   lResponse: String;
begin
  lJSO := SO('{"name": "Henri Gourvest", "vip": true, "telephones": ["000000000", "111111111111"], "age": 33, "size": 1.83, "adresses": [ { "adress": "blabla", "city": "Metz", "pc": 57000 }, { "adress": "blabla", "city": "Nantes", "pc": 44000 } ]}');
  lRequest := TStringStream.Create(lJSO.AsString,TEncoding.UTF8);   // or ASCII
//  showmessage(lRequest.DataString);  Correct data
  IdHTTP.Request.ContentType := 'application/json';
//  idHTTP.Request.Charset := 'utf-8';
  lResponse := IdHTTP.Post('http://localhost:8085/ttposttest',lRequest);
//  ShowMessage(lResponse.dataString);
  lRequest.Free;
  lJSO := nil;
end;

Receiver is a TWebAction on a TWebModule, set for MethodType mtPost (or mtAny) with handler:

procedure TWebModuleWebServices.WebModuleWebServicesTTPostTestAction(
  Sender: TObject; Request: TWebRequest; Response: TWebResponse;
  var Handled: Boolean);
var S: String;
begin
   S := Request.Query;
   Handled := true;
end; { WebModuleWebServicesTTPostTestAction }

Request.Query is empty.
All VCL apps. I have read these SO posts and many others but must be overlooking something...

TIA, Jan

Community
  • 1
  • 1
Jan Doggen
  • 8,799
  • 13
  • 70
  • 144

1 Answers1

0

The TWebRequest.Query property returns the URL query string, which you are not sending any. That is why it is blank. Your POST data is accessible from the TWebRequest.Content and TWebRequest.RawContent properties instead.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770