def words url = "https://aip.baidubce.com/rpc/2.0/nlp/v1/lexer?access_token=1111111" params = '{ "text": "百度是一家高科技公司" }' params.encode! "GBK", "UTF-8" res = RestClient::Request.execute(:method=> :post, :url=> url, :payload=> params, :content_type => "application/json; charset=GBK", :accept => :json) #或res = RestClient.post url, params, {:content_type => "application/json; charset=GBK", :accept => :json} puts res.body.encode! "UTF-8", "GBK" end
; charset=GBK 可以不加,将已经编码好的数据传送即可
百度要求传递的数据是以下格式。“不能换成‘,这一点一定注意。以下整个结构都要作为字符串传递过去
{ "text": "百度是一家高科技公司" }