rest-client restclient get post写法
Posted znsongshu
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了rest-client restclient get post写法相关的知识,希望对你有一定的参考价值。
get
url = "https://api.weixin.qq.com/sns/jscode2session" data = { appid: "××××", secret: "×××××", js_code: params[:code].to_s, grant_type: ‘authorization_code‘ } response = RestClient.get url, params: data, :accept => :json body = JSON.parse(response.body)
post
url = "https://aip.baidubce.com/rpc/2.0/nlp/v1/lexer?access_token=××××××"
posts = {text: "8888"} posts.encode! "GBK", "UTF-8"//如果需要编码再用这个 res = RestClient.post url, posts, :content_type => "application/json", :accept => :json res.encode! "UTF-8", "GBK" res = JSON.parse(res.body)
以上是关于rest-client restclient get post写法的主要内容,如果未能解决你的问题,请参考以下文章
RESTClient 3.5 发布,RESTful 测试工具
我如何处理rest-client 500错误响应并不断在我的循环中抓取?