c#中的Ruby ASCII-8BIT编码等效

时间:2017-07-03 07:06:28

标签: c# ruby-on-rails ruby

我正在尝试将以下代码从ruby转换为C#:

open(file_path, ’rb’) do |doc|
    response = RestClient::Request.execute :method => :post,
                 :url => "http://something.com",
                 :payload => {
                 :document => doc
                 }

我的理解是这将按照以下文档读取ASCII-8BIT中的二进制文件:

"b"  Binary file mode
     Suppresses EOL <-> CRLF conversion on Windows. And
     sets external encoding to ASCII-8BIT unless explicitly
     specified.

因此,尝试在C#中复制此示例代码,我写道:

string myString;
Encoding enc = Encoding.GetEncoding(????);

using (FileStream fs = new FileStream("D:\\sample1page.pdf", FileMode.Open))
        using (BinaryReader br = new BinaryReader(fs, enc))
        {
            byte[] bin = br.ReadBytes(System.Convert.ToInt32(fs.Length));
            myString = enc.GetString(bin);
        }

所以问题是我需要做什么编码?是在ruby

中使用等效的ASCII-8BIT

0 个答案:

没有答案