title: How to convert a Net::HTTP response to a certain encoding in Ruby 1.9.1?
body: <p>I have a Sinatra application (<a href="http://analyzethis.espace-technologies.com" rel="noreferrer">http://analyzethis.espace-technologies.com</a>) that does the following </p>
  
  <ol>
  <li>Retrieve an HTML page (via net/http)</li>
  <li>Create a Nokogiri document from the response.body</li>
  <li>Extract some info and send it back in the response. The response should be UTF-8 encoded</li>
  </ol>
  
  <p>So I came to the problem while trying to read sites that use windows-1256 encodings like www.filfan.com or www.masrawy.com.</p>
  
  <p>The problem is the result of the encoding conversion is not correct though no errors are thrown.</p>
  
  <p>The net/http response.body.encoding gives ASCII-8BIT which can not be converted to UTF-8</p>
  
  <p>If I do Nokogiri::HTML(response.body) and use the css selectors to get certain content from the page - say the content of the title tag for example - I get a string which when i call string.encoding returns WINDOWS-1256. I use string.encode("utf-8") and send the response using that but again the response is not correct.</p>
  
  <p>Any suggestions or ideas about what's wrong in my approach?</p>