【发布时间】:2017-12-07 00:26:23
【问题描述】:
我正在使用 rest-client 向某个地址发出 post 请求。不幸的是,rest-client 不断将网络地址从“https”更正为“http”。然后返回一个错误。
我已经查看了文档,这是否可能是 gem 的设置。任何人都知道我如何“强制”rest-client 访问所需的地址。
提前谢谢!
使用的代码是:
uri = 'https://sandbox.api.online.unit4.nl/V19/OAuth/Token'
payload = {
code: params[:code],
client_id: '#{@client_id}',
client_secret: '#{@client_secret}',
redirect_uri: '#{@client_redirect_url}',
grant_type: 'authorization_code'
}
response = RestClient::Request.execute(method: :post, url: uri, headers: {params: payload})
卷曲:
> GET /V19/OAuth/Token HTTP/1.1
> Host: sandbox.api.online.unit4.nl
> User-Agent: curl/7.54.0
> Accept: */*
>
< HTTP/1.1 400 Bad Request
< content-length: 27
< content-type: application/json; charset=utf-8
< date: Wed, 06 Dec 2017 15:21:44 GMT
< p3p: CP="NON CUR OTPi OUR NOR UNI"
< server: Microsoft-IIS/7.5
< x-aspnetmvc-version: 5.2
< cache-control: no-cache, no-store, max-age=0, must-revalidate
< access-control-allow-origin: *
< x-powered-by: ASP.NET
< x-aspnet-version: 4.0.30319
< pragma: no-cache
< Set-Cookie: PD_STATEFUL_88eb7504-dfe9-11e2-8624-005056af4a32=sandbox.api.online.unit4.nl; Path=/
< Set-Cookie: LB_online_unit4=1493375404.20480.0000; path=/
【问题讨论】:
-
你能把你正在使用的代码过去吗?另外,您确定没有重定向吗?
curl -v YOUR_HTTPS_ADDRESS返回什么?
标签: ruby-on-rails ruby rest-client