linux curl save as utf-8

后端 未结 2 663
栀梦
栀梦 2021-01-04 06:18

Trying to use linux curl to download an xml file from an url.

Pretty sure that the xml is encoded in UTF-8,

suspecting curl -o doesnt save as UTF-8.

相关标签:
2条回答
  • 2021-01-04 06:52

    Have you tried adding the Accept-Charset header? I had a similar issue downloading a file which was downloading with the wrong encoding. When I set the Accept-Charset header it works:

    curl -H "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7" URL | iconv -f iso8859-1 -t utf-8 > output.xml
    
    0 讨论(0)
  • 2021-01-04 07:10

    curl does not do any conversion of the file it downloads. If the HTTP server serves you the XML in another encoding (e.g., ISO8859-1) that his how curl will save it to disk too.

    To workaround your problem, you can use "iconv" as follows:

    curl URL | iconv -f iso8859-1 -t utf-8 > output.xml
    

    Hope this help.

    0 讨论(0)
提交回复
热议问题