来自rails app上的gcloud ruby​​的401身份验证错误

时间:2017-08-28 10:24:10

标签: api ruby-on-rails-4 basic-authentication gcloud

我在gcloud上的rails后端项目上设置了ruby,现在当我尝试使用wp_remote_get() API中的json方法将数据提取到WordPress网站时。

https://gcloud-assigend-domain.com/api/v1/auth/signin
  

gcloud正在给我401认证,

虽然同样的事情在我的本地主机上工作正常。

通过wp页面我向API发送用户电子邮件和密码,这样我就可以获得令牌访问权限,客户端ID,uid和到期时间。

如果有人意识到这一点,请帮助我。

1 个答案:

答案 0 :(得分:0)

我忘了将标题设置为'Content-Type' => 'application/x-www-form-urlencoded',

所以我只是将标题添加到wp_remote_post()方法并修复了问题。

'headers' => array(
    'Content-Type' => 'application/x-www-form-urlencoded',
),