2013-07-25 17 views
0

我無法讓我的服務器應用程序正確接收任何東西。與TIdHTTP.Post張貼沒有收到JSON數據

使用設計時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; 

接收機是在一個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應用程序。我已閱讀theseSOposts和其他許多人,但必須忽視的東西...

TIA,揚

回答

0

TWebRequest.Query屬性返回URL查詢字符串,你不發送任何。這就是爲什麼它是空白的。您的POST數據可通過TWebRequest.ContentTWebRequest.RawContent屬性進行訪問。