我在使用 Idhttp.Get 方法时遇到了一些问题。我认为它默认在阻塞模式下工作(等待答案转到下一行),但我只是看到它没有等待答案转到另一行。我将它与线程一起使用,但我认为这不是问题。代码是:
IdHTTP1:= TIdHttp.Create(Application);
IdHTTP1.ConnectTimeout:= 10000;
IdHTTP1.Request.Clear;
IdHTTP1.Request.BasicAuthentication:= true;
IdHTTP1.Request.Username := Username;
IdHTTP1.Request.Password := Password;
try
IdHTTP1.Get(PbxURL); **//this should STOP here and wait for answer don't?**
HttpCode:= IdHTTP1.ResponseCode;
except
on E: EIdHTTPProtocolException do
HttpCode := IdHTTP1.ResponseCode;
end;
if HttpCode=200 then
Memo1.Lines.Append('Valid Get!');
所以,我只是注意到我没有得到正确的 HttpCode 值,因为在“获取”方法之后,它只是继续执行而不等待“获取”完成。我怎么解决这个问题??