Recent

Author Topic: [SOLVED] TFPHTTPClient doesn't work with HTTP response 206 Partial Contect ?  (Read 1800 times)

krexon

  • Jr. Member
  • **
  • Posts: 80
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?

« Last Edit: October 22, 2019, 08:13:44 pm by krexon »

Thaddy

  • Hero Member
  • *****
  • Posts: 14364
  • Sensorship about opinions does not belong here.
Re: TFPHTTPClient doesn't work with HTTP response 206 Partial Contect ?
« Reply #1 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)
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

krexon

  • Jr. Member
  • **
  • Posts: 80
Re: TFPHTTPClient doesn't work with HTTP response 206 Partial Contect ?
« Reply #2 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.  

Handoko

  • Hero Member
  • *****
  • Posts: 5150
  • My goal: build my own game engine using Lazarus
Re: TFPHTTPClient doesn't work with HTTP response 206 Partial Contect ?
« Reply #3 on: October 22, 2019, 01:20:12 pm »

krexon

  • Jr. Member
  • **
  • Posts: 80
Re: TFPHTTPClient doesn't work with HTTP response 206 Partial Contect ?
« Reply #4 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.

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2020
  • Former Delphi 1-7, 10.2 user
Re: TFPHTTPClient doesn't work with HTTP response 206 Partial Contect ?
« Reply #5 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...

krexon

  • Jr. Member
  • **
  • Posts: 80
Re: TFPHTTPClient doesn't work with HTTP response 206 Partial Contect ?
« Reply #6 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.
« Last Edit: October 22, 2019, 08:01:31 pm by krexon »

 

TinyPortal © 2005-2018