1

I have following code which return data from httpclient, but it looks like it's not giving data in proper json format.

Below is code and response.

HttpClient client = new HttpClient();
client.MaxResponseContentBufferSize = 2147483647;
client.DefaultRequestHeaders.Add("Accept", "*/*");
client.DefaultRequestHeaders.Add("Accept-Encoding", "gzip, deflate, br");

var response = await client.GetAsync("URL");
Var data = await response.Content.ReadAsStringAsync();

Data is coming it looks like this:

`"\u001f�\b\0�аf\0\u0003���r\u001bW���WA�Z�s�<�/:H��e\u001dMA���\u000e\aD�\"J$ ����\u0015�J�\u0010�d�\0A2OT\u0002Ā�s���e\u0013,p\u0010@~\u001aY����\u007f\u001f|>\u001b�=\u001e}y��A?�����xv2z�\u007f0�q��˫��ޯ\u000f\u001e>8\u001a�\u001f��?���I�P�\vOO\u001fv\u001eMO����:\u007f�g�OL���x<\u001bu��'G��䨳\u007f6��\u0019\f'�������_\u0017��\v���Ë�N��㏓�Q�p4���\u001evf��Igt�qt��$���.����� L�0M���N�C�y�����Ő�G���\u001c��O�f���\u001ff���0�F\u0013Ea�[��������\a�\u0017gg����Gӣ�3�<~p��6��>�|��7��?{{�E��yYc��خ\u0003��ͰfϘwu�l:����w��\u001c\u001e�c�tS���TiM�$�i\\s)�]/��x~)ش�{��X�˳4S���L�q&�KM���*�.g�\u001bg�{��o..."
4
  • HttpClientHandler.AutomaticDecompression Property Commented Aug 5, 2024 at 13:41
  • @AlexanderPetrov I have already set client.DefaultRequestHeaders.Add("Accept-Encoding", "gzip, deflate, br"); Commented Aug 5, 2024 at 14:33
  • stackoverflow.com/a/69222690/5045688 Commented Aug 5, 2024 at 15:01
  • Just curious why you are not doing the following * To return JSON from the server, you must include the JSON data in the body of the HTTP response message and provide a "Content-Type: application/json" response header. The Content-Type response header allows the client to interpret the data in the response body correctly. also look at this previously asked question that was answered and accepted - stackoverflow.com/questions/73512159/… Commented Nov 13 at 17:56

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.