【问题标题】:JSON data posted with TIdHTTP.Post not received未收到使用 TIdHTTP.Post 发布的 JSON 数据
【发布时间】:2013-07-25 14:56:57
【问题描述】:

我无法让我的服务器应用正确接收任何内容。

使用设计时 TIdHTTP 组件的发送方代码,带有属性
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 是 TWebModule 上的 TWebAction,设置为 MethodType mtPost(或 mtAny),带有处理程序:

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 为空。
所有 VCL 应用程序。我已经阅读了these SO posts 和许多其他内容,但一定忽略了一些东西......

TIA,一月

【问题讨论】:

    标签: json delphi http delphi-xe2


    【解决方案1】:

    TWebRequest.Query 属性返回 URL 查询字符串,您不会发送任何内容。这就是为什么它是空白的。您的POST 数据可以从TWebRequest.ContentTWebRequest.RawContent 属性中访问。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-12-25
      • 2013-02-14
      • 1970-01-01
      • 2016-10-06
      • 1970-01-01
      • 2017-08-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多