[英]How to read response from Indy IdHTTP get
我已經編寫了與Indy IdHTTP組件一起使用的代碼
var
get_url: string;
resp: TMemoryStream;
begin
get_url := 'http://localhost/salesapp/is_run.php?ser=';
resp := TMemoryStream.Create;
IdHTTP1.Get(get_url+'v', resp);
memo1.Lines.LoadFromStream(resp);
該URL http://localhost/salesapp/is_run.php?ser=v
返回JSON響應,但我不知道如何從Delphi讀取它。
當Get()
退出時,流的Position
位於流的末尾。 您需要在調用LoadFromStream()
之前將Position
重置為0,否則將沒有任何加載:
var
get_url: string;
resp: TMemoryStream;
begin
get_url := 'http://localhost/salesapp/is_run.php?ser=';
resp := TMemoryStream.Create;
try
IdHTTP1.Get(get_url+'v', resp);
resp.Position := 0; // <-- add this!!
memo1.Lines.LoadFromStream(resp);
finally
resp.Free;
end;
end;
另一種方法是刪除TMemoryStream
然后讓Get()
返回JSON作為String
:
memo1.Text := IdHTTP1.Get(get_url+'v');
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.