linux - curl 命令输出编码错误

标签 linux bash curl

当我执行

curl "http://weather.yahooapis.com/forecastrss?w=1225955&u=c" 

它用不正确的编码返回响应:

khan@khan-P55A-UD3P:~$ curl "http://weather.yahooapis.com/forecastrss?w=1225955&u=c" 
���dž��ud@3��v(
����$j$��~����4(���Xy����wH�o�9<q��,�s\��e"�tA�\݌h�ʄ���
                                                             �����h��M���{���J=�m93W
                                                                                      �S�)�e�[sv,�҉eAKM�z{ǔ��g��:���*�����(n�m��&�Jꟈ��Mg�,yn?F�&��_��
ik6                                                                                                                                                      >��0�e&X��簺
sQ~�:�Z;*9�.a"ߕ|��EO[�5"�׫[�k�����1ӆ�n?}r1�u�d��Cڐ��X��`�NF�g!�c��W��G��1�o����Z��53<z`���.��w� s׃��ߖ+�vh��3yt�b}�9
�6�s3K
�W�  �0�هF@���>�X֥Qh�ʰv�BQ�R
ʮ�<�4;�ڊ2�8y� �g���6M(��]�|'�U@�ș�B
�8du!�&'�NOB��ț��3�K��fW��
                           \Rheg�=��F�R;�u�F�s9���&����,��|r��o�E۲�T��V$&�����uf\������v��Z~&�Au��{��ى"m�ʨ���U����2�8�#0F@'������
                                                                                                                                           l���R�XL��~A��̱���p��9��8�iH��nC�i4��^t;����۪���d�V�����7��=S&��2�u�#v~�L`�k���v�0
                            �[���"<���~�z��j,���X=�zmKD/|���(�p��M���⥁}_�!��GџC��2|�G��<ফe��nb"x ?�e�s��;���r;ﲃ�]�9"l��;�}�w�ٮjwR[�C����#O�
                                                                                                                                                      �������#a����s�km���$a�����\)�$�o��Ә�K��FR�*�ý�l�Z
            �
             &�`_�D�WӠ�>`T��0��| c��⿎K%��n:���~(�����.{��}< /~�^!A��$\���c�<�Á
"��k�_��t����t�n�5�^t�وF��l<V�����oo?
                                        `O���3p��ĝ�S�X�G�x��Ź+�
khan@khan-P55A-UD3P:~$ 

但是,相同的命令在另一台计算机上工作得很好。 我需要在 shell 中设置什么才能以正确的格式获取它吗?

我正在使用 ubuntu 14.04 64 位。(Linux khan-P55A-UD3P 3.13.0-40-generic#69-Ubuntu SMP Thu Nov 13 17:53:56 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux)

有什么想法吗?命令的屏幕截图也可以在这里看到:http://i.imgur.com/QDy7F7i.png

最佳答案

如果设置 --compressed 标志,curl 将自动解压缩响应:

curl --compressed "http://example.com"

--compressed (HTTP) Request a compressed response using one of the algorithms libcurl supports, and save the uncompressed document. If this option is used and the server sends an unsupported encoding, curl will report an error.

refrence of answer

如果您只需要将此选项用于 gzip 内容编码,请使用此命令

curl -sH 'Accept-encoding: gzip' http://example.com/ | gunzip -

关于linux - curl 命令输出编码错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27200504/

相关文章:

python - MATLAB 生成的 Python 包与 Ubuntu 上的 PyQt5 冲突——可能是库问题

python - 递归遍历目录并替换函数调用

performance - 如何在不使用 echo 的情况下 awk 或 grep 变量?

ssl - 通过 TLS 下载时,Curl 在 XP 上出错

javascript - 使用 React 和 axios 进行 curl

linux - perforce 命令以了解非版本化文件

linux - 没有任何交换分区的虚拟内存

bash - 将 bash $$ 值保存在变量中

curl - 在Docker Swarm上无法访问已发布的服务

python pip安装scipy报错