简体   繁体   中英

Rails incompatible character encodings: UTF-8 and ASCII-8BIT

In my Rails app,I send a post request:

require 'net/http'
url="http://192.168.0.84:809/Services/SDService.asmx/UserRegister"
Net::HTTP.post_form(URI(url),{:memtyp=>'CU',:memid=>'100867',:dob=>'1989-01-01'}).body

But I got the error:

incompatible character encodings: UTF-8 and ASCII-8BIT

I found that the response data include UTF-8 character just like 中文 ,and then I got this error.

so what should I do?

You can send data in json format if you want to do so you can do this by following:

require 'rest_client'
require "net/http"
require "uri"
require 'json'


RestClient.post 'localhost:3001/users',{:memtyp=>'CU',:memid=>'100867',:dob=>'1989-01-01'}.to_json , :content_type => :json, :accept => :json

Plese change the localhost url to actual url you want to hit.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM