Lazarus

Programming => Networking and Web Programming => Topic started by: krexon on October 22, 2019, 12:10:44 pm

Title: [SOLVED] TFPHTTPClient doesn't work with HTTP response 206 Partial Contect ?
Post by: krexon on October 22, 2019, 12:10:44 pm
I had never any problems with TFPHTTPClient.
Until now :(
Response of server is 206 (Partial Content). It is outside of my control. I don't use range.
I can't get JSON response body. Instead of JSON, I receive only 3 chars: %1F%3F%08 (unit separator, question mark, backspace).

What to do with this problem?

Title: Re: TFPHTTPClient doesn't work with HTTP response 206 Partial Contect ?
Post by: Thaddy on October 22, 2019, 12:28:38 pm
What to do? Show code that reproduces it. (And your FPC version, Lazarus version and platform/OS)
Title: Re: TFPHTTPClient doesn't work with HTTP response 206 Partial Contect ?
Post by: krexon on October 22, 2019, 01:10:09 pm
It's simple HTTP POST. I used it several times and I had no problems when there was response code '200 OK'. For the first time I came across that server server response is '206 Partial Content'. In this case TFPHTTPClient can't get proper response body.

Code: Pascal  [Select][+][-]
  1. uses ..., fphttpclient, opensslsockets, ...
  2.  
  3. with TFPHTTPClient.Create(nil) do
  4.   try
  5.       AddHeader('Content-Type', 'application/json; charset=UTF-8');
  6.       AllowRedirect := True;
  7.       RequestBody := TStringStream.Create('{JSON}');
  8.       Memo.Lines.Add(Post('https://url'));
  9.   finally
  10.     RequestBody.Free;
  11.     Free;
  12.   end;
  13.  
Title: Re: TFPHTTPClient doesn't work with HTTP response 206 Partial Contect ?
Post by: Handoko on October 22, 2019, 01:20:12 pm
Maybe it is the SSL issue which discussed recently:

https://forum.lazarus.freepascal.org/index.php/topic,39206.msg308413.html#msg308413
Title: Re: TFPHTTPClient doesn't work with HTTP response 206 Partial Contect ?
Post by: krexon on October 22, 2019, 01:40:22 pm
No, it's not SSL problem. Everything works fine, except this one case.
Other requests (GET and POST) to the same server, but different endpoints, works fine.
Title: Re: TFPHTTPClient doesn't work with HTTP response 206 Partial Contect ?
Post by: trev on October 22, 2019, 01:49:55 pm
I've only ever seen HTTP 206 code responses for range requests. What is the web server software being used which gives the 206 responses? I suspect a bug...
Title: Re: TFPHTTPClient doesn't work with HTTP response 206 Partial Contect ?
Post by: krexon on October 22, 2019, 02:05:42 pm
I don't know what web server is there.
When I make the same request in different software (i.e. Visual Studio Code), there is also response with code 206, but there is also proper JSON in response body.

EDIT:
I tested it with standard HttpClient in Delphi 10.3.2 and I get proper JSON response. Of course response code is 206 :)

EDIT2:
I used Indy in Lazarus and response is the same like with fphttpclient (only 3 chars) :(

EDIT3:
I made simple console application in Lazarus to easy compile with different version of fpc. After compiling program with FPC version I use now 3.3.1 rev 43202 I saw in console that response is much longer than 3 chars. It is:
Code: Pascal  [Select][+][-]
  1.       íýGŽ$IŇĽ˙_% kK?t9÷]´g 3˛"#'ČE"P°t 7"┼yŔÍ<?DÜ˝ŕîYQžé'* 6?XD¨¨ą«ë#ęfËĐ┼ć'!0B? J/?"JÚa<'Ą┼(!? 'Úp<[%"p3qYBa:'47"ÓŢż4?o"XçJĆÂ]˙îR˙ŃţÄeĆd&Ívn¸cď9t*(_ŻĄÖ2Wü!Â"Ĺ (Ä3/'+\Ą|˙ÄeÖ¨|('"/ŤXl7Uú|1ë˙żZŚ┼ă ČňgˇMÄu:6Ęu??z'TRŇw"&ä×Âi.ŃKŇű*cRĐč/°c?RRgĆ\§Ú.&;ôÖŇJĹž|[CH=lx!|<ţÁWbĆŤĐ3aĘB%ÂGžiŃčĺC&ăZŞ8+' ÇyÝhňvčC 7<RţGŁÉ|p
  2. ÄÁŽ?ŕtÍŻú?Î?mŰ?vˇěč?XÎcDŘ!'ŔÇ-".&Á>đJÄP7'ćYO'Ŕ¤b-t_%?L¬E]Ń=u[v Ďđň,YYž<Y×.H%ďcőué       Ř{V"!h+ěűű@
  3. vËÝr÷žÔ¬p  @1q;?Ř4ŔížďŐŻí.ďŢfR┼o¨xP`ËE ČňĐśe!A°ZóUŐ§E*z>"ß?Âl{R÷Tnz<6ňITĚň¤Ę%fóď!a¸Ěš<52

EDIT4:
Finally I managed to make it work :)
I added request header and it returns proper JSON in body
Code: Pascal  [Select][+][-]
  1. xxx-language : en-GB
I don't know why it has be added only in lazarus and not elsewhere.
TinyPortal © 2005-2018