Reputation: 303
I'm having some problems with the Idhttp.Get method. I thought it's by default working in blocking-mode(wait for the answer to go to next line), but I just saw it's not waiting for the answer to go to another line. I'm using it with threads, but I think that's not the problem. The code is:
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!');
So, I just notice that i'm not getting the right HttpCode value because after the 'Get' method, it just continue the execution without waiting for the 'Get' complete. How can I solve this problem??
Upvotes: 0
Views: 2140
Reputation: 163357
You say you're not getting the right HttpCode, which suggests you are getting an HttpCode, and that means the Get method has waited as long as it needed to to get a result.
If the response code you get is 301, then you should try setting the HandleRedirects property so it will automatically re-issue the request using the returned address. Otherwise, you'll have to handle the response yourself.
The Get function does not return prematurely. You're misinterpreting what you've observed.
Upvotes: 5