So this used to work without a hitch but now I get a “Socket Error #10054 Connection reset by peer.”
I assume it started happening once I updated my Indy packages. Today was my first time running the code since then.
Can anyone explain how the update might have changed the behavior of this code And how to resolve it?
Thank You
function PostData(url : string; param: TStringList) : string;
var
text: string;
sHttpSocket: TIdHTTP;
sshSocketHandler: TIdSSLIOHandlerSocketOpenSSL;
resStream: TStringStream;
begin
sHttpSocket := TIdHTTP.create;
sshSocketHandler := TIdSSLIOHandlerSocketOpenSSL.create;
sHttpSocket.IOHandler := sshSocketHandler;
sHttpSocket.Request.ContentType := 'application/x-www-form-urlencoded';
sHttpSocket.Request.Method := 'POST';
resStream := TStringStream.create;
sHttpSocket.Post(url, param, resStream);
resStream.Seek(0, soFromBeginning);
text := resStream.DataString;
result := text;
end;
If you are posting to an HTTPS url, make sure the
TIdSSLIOHandlerSocketOpenSSLis configured properly for the server you are trying to connect to. Chances are, the defaults might not be matching up with what the server is actually expecting. In particular, theTIdSSLIOHandlerSocketOpenSSL.MethodandTIdSSLIOHandlerSocketOpenSSL.SSLVersionsproperties default to TLSv1, but maybe the server does not support TLSv1.On a side note,
TStringStreamoperates differently in D2009+ than it did in earlier versions, so I would suggest you avoid it and let Indy decode the Text for you: