I am trying to intercept GET/POST that i get from IdHTTPProxyServer and send it to IdHTTP so i can replicate the GET/POST and eventually get cookies so I can login in to any website.
How can this be improved? If i try to execute this code it crashes.
procedure TForm1.IdHTTPProxyServer1HTTPDocument(
AContext: TIdHTTPProxyServerContext; var VStream: TStream);
begin
if AContext.Command='POST' then begin
EmbeddedWB1.LoadFromString(IdHTTP1.Post(AContext.Target,AContext.Headers.Text)); << CRASH
end;
if AContext.Command='GET' then begin
EmbeddedWB1.LoadFromString(IdHTTP1.Get(AContext.Target)); << CRASH
end;
end;
When using the
OnHTTPDocumentevent, you need to look at theTIdHTTPProxyServerContext.TransferSourceproperty to know if the event is being triggered for a client request that contains body data, or is being triggered for the target server’s response to the client request. Sending your ownGET/POSTrequest only makes sense when processing client requests, however theOnHTTPDocumentevent is not likely to ever be triggered for aGETrequest since there is no body data to capture.You don’t need to use
TIdHTTPin order to get the server’s cookies. LetTIdHTTPProxyServerdo its work normally, and then you can extract the cookies from theTIdHTTPProxyServerContext.Headersproperty in theOnHTTPResponseevent, eg: