mercredi 4 novembre 2015

Encoding type of byte[] from Weblient (with post)

I'm trying to download an NZB file from binsearch.com programmatically. I'd achieved this with this code:

private static void DownloadNZB()
{
    var url = "http://ift.tt/1MixzpY";
    System.Net.ServicePointManager.Expect100Continue = false;
    using (var client = new WebClient())
    {
        var values = new NameValueCollection
            {
                { "action", "nzb" },
                { "192636313", "checked" }
            };
        byte[] result = client.UploadValues(url, values);
        byte[] converted = Encoding.Convert(Encoding.GetEncoding("iso-8859-1"), Encoding.UTF8, result);
        string resultstring = System.Text.Encoding.UTF8.GetString(converted);
    }
}

It works like a charm, except for the encoding. When I download the NZB, it contains the following header:

<?xml version="1.0" encoding="iso-8859-1" ?>

So I'll guess it is Code Page 1252 (ISO 8859-1), as it says in the header.

This value is set to resultstring in the last line of working code:

\u001f\u008b\b\0\0\0\0\0\0\u0003å\u009d[o\W\u0015Çß\u0091ø\u000e\u0083\u0091PQäãuÛ7HBÕ\v\b©*<À\u0003 \u001eìd\u0092\u001a\u0012;Ì\u008c{ûô¬=­ÈÙÃY\u0095ù\u0093\u0019«ÊCl«µÿ3sÎ^kÿöº\u009dÇ¿ùúõ«Õ\u0097ëÍöúöæÉ\u0019Ot¶Zß<»}~}óòÉÙõöö¼ÖÔÎùlõ\u009b§?ýÉã\u009f}ò...

Which type encoding is this, or is something wrong with my code?




Aucun commentaire:

Enregistrer un commentaire