title: Rails: How to send a http get request with UTF-8 encoding
body: <p>I'm trying to use an external API to get some information</p>
  
  <pre><code>  address=self.address
    response = HTTParty.get("http://api.map.baidu.com/geocoder/v2/?address=#{address}&amp;output=json&amp;ak=5dfe24c4762c0370324d273bc231f45a")
    decode_response =  ActiveSupport::JSON.decode(response)
  </code></pre>
  
  <p>However, the <code>address</code> is in chinese, so I need to convert into UTF-8 code, 
  if not I'll get <code>URI::InvalidURIError (bad URI(is not URI?):</code> How to do it?</p>
  
  <p>I tried <code>address=self.address.force_encoding('utf-8')</code>, but it does not work, maybe I should use other method instead?</p>
  
  <p>UPDATE:</p>
  
  <pre><code>  uri = "http://api.map.baidu.com/geocoder/v2/?address=#{address}&amp;output=json&amp;ak=5dfe24c4762c0370324d273bc231f45a"
    encoded_uri = URI::encode(uri)
    response = HTTParty.get(encoded_uri)
    decode_response =  ActiveSupport::JSON.decode(response)
    self.latitude = decode_response['result']['location']['lat']
  </code></pre>
  
  <p>and I get <code>can't convert HTTParty::Response into String</code>. What's wrong with it?</p>
  
  <p><a href="https://stackoverflow.com/questions/9814456/extracting-values-from-a-hash">I found something here</a>, I think I'll need to tell Httparty explicityly to parse it with JSON?</p>