I have troubles sending an XMLHttpRequest
request with TIdHTTP
. Here is my header:
Content-Type:application/x-www-form-urlencoded; charset=UTF-8
Cache-control:no-cache
Connection:keep-alive
DNT:1
Faces-Request:partial/ajax
X-Requested-With:XMLHttpRequest
Accept:application/xml, text/xml, */*; q=0.01
Accept-Language:de-DE
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko
Accept-Encoding:gzip, deflate
Content-Length:517
Here is the response header:
(Status-Line):HTTP/1.1 200 OK
Date:Mon, 21 Jun 2021 01:02:28 GMT
Server:Apache
X-ISPI-PERF:[Apache D=28068us b=0%]
X-ISPI-REQ-ID:xxxxxxxxxxxxxxxxxxxx
X-UA-Compatible:IE=edge
Pragma:no-cache
Cache-Control:no-cache, no-store
Expires:Thu, 01 Jan 1970 00:00:00 GMT
Cache-Control:no-cache
Content-Type:text/xml;charset=UTF-8
X-Frame-Options:SAMEORIGIN
Set-Cookie:JSESSIONID=xxxx; Path=/air; Secure
Vary:Accept-Encoding,User-Agent
X-Content-Type-Options:no-sniff
Strict-Transport-Security:max-age=[; includeSubDomains]
X-XSS-Protection:1; mode=block
Keep-Alive:timeout=5, max=98
Connection:Keep-Alive
Content-Length:9642
How can I handle the response to get the full Content every time? The problem is that sometimes I get only 2000 bytes instead of 9600. There is no difference if I use a TMemoryStream
or a String
to get the response.
Here is my code:
idHttpA := TIdHTTP.Create(nil);
idHttpA.HTTPOptions := [hoTreat302Like303];
lIOHandlerA := TIdSSLIOHandlerSocketOpenSSL.Create(nil);
lIOHandlerA.SSLOptions.Mode := sslmClient;
lIOHandlerA.SSLOptions.SSLVersions := [sslvTLSv1, sslvTLSv1_1, sslvTLSv1_2];
//lIOHandlerA.SSLOptions.Method := sslvTLSv1_2; *must be deleted because of SSLVersions
idHttpA.IOHandler := lIOHandlerA;
....
try
res := idHttpA.Post('https://server/Start.xhtml', List);
except
on e:EIdSocketError do
ShowMessage('EIdSocketError: ' + e.Message);
on e:EIdReadTimeout do
ShowMessage('EIdReadTimeout: ' + e.Message);
on e:EIDHttpProtocolException do
ShowMessage('EIDHttpProtocolException: ' + IntToStr(e.ErrorCode));
on e:Exception do
ShowMessage('Exception: ' + e.Message);
end;
Following is the response headers I get via TIdHTTP.Response.RawHeaders
:
Date: Mon, 21 Jun 2021 18:30:22 GMT
Server: Apache
X-ISPI-PERF: [Apache D=45046us b=2%]
X-ISPI-REQ-ID: xxxxxxxxxxxxxxxxxxx
X-UA-Compatible: IE=edge
Pragma: no-cache
Cache-Control: no-cache, no-store
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Cache-Control: no-cache
Content-Type: text/xml;charset=UTF-8
X-Frame-Options: SAMEORIGIN
Set-Cookie: JSESSIONID=xxxx.3; Path=/air; Secure
Vary: Accept-Encoding,User-Agent
Content-Encoding: gzip
X-Content-Type-Options: no-sniff
Strict-Transport-Security: max-age=[; includeSubDomains]
X-XSS-Protection: 1; mode=block
Connection: close
The problem was that HTTPAnalyzer show different response header to TIdHTTP,
after i check ResponseHeaders with TIdHTTP.Response.RawHeaders
, i got response Content-Encoding: gzip
, that didn't show HTTPAnalyzer, than i add Compressor
idHttpA.Compressor := TIdCompressorZLib.Create(idHttpA)
and the code working fine.
Thank you @RemyLebeau.