" HTTP 302暂时移动"当使用Rails在Cloud9上进行CURL时

时间:2015-05-14 21:27:09

标签: ruby-on-rails ruby curl cloud9-ide http-status-code-302

我有一个简单的APP会接受创建事件的请求。它应该使用URL并检查RegisteredApplication,如果找到了,它应该创建一个链接到该RegisteredApplication的事件。

问题在于,它似乎无法在Cloud9上运行!这是我在执行Curl命令时得到的响应:

* Hostname was NOT found in DNS cache
*   Trying 104.154.33.155...
* Connected to blocmetrics-klaha1.c9.io (104.154.33.155) port 443 (#0)
* successfully set certificate verify locations:
*   CAfile: none
  CApath: /etc/ssl/certs
* SSLv3, TLS handshake, Client hello (1):
* SSLv3, TLS handshake, Server hello (2):
* SSLv3, TLS handshake, CERT (11):
* SSLv3, TLS handshake, Server key exchange (12):
* SSLv3, TLS handshake, Server finished (14):
* SSLv3, TLS handshake, Client key exchange (16):
* SSLv3, TLS change cipher, Client hello (1):
* SSLv3, TLS handshake, Finished (20):
* SSLv3, TLS change cipher, Client hello (1):
* SSLv3, TLS handshake, Finished (20):
* SSL connection using ECDHE-RSA-AES256-SHA384
* Server certificate:
*        subject: OU=Domain Control Validated; OU=EssentialSSL Wildcard; CN=*.c9.io
*        start date: 2015-03-17 00:00:00 GMT
*        expire date: 2016-05-03 23:59:59 GMT
*        subjectAltName: blocmetrics-klaha1.c9.io matched
*        issuer: C=GB; ST=Greater Manchester; L=Salford; O=COMODO CA Limited; CN=COMODO RSA Domain Validation Secure Server CA
*        SSL certificate verify ok.
> POST /api/events HTTP/1.1
> User-Agent: curl/7.35.0
> Host: blocmetrics-klaha1.c9.io
> Accept: application/json
> Origin: keeblerheaney.net
> Content-Type: application/json
> Content-Length: 17
> 
* upload completely sent off: 17 out of 17 bytes
< HTTP/1.1 302 Moved Temporarily
< Location: https://c9.io/api/nc/auth?response_type=token&client_id=proxy&redirect=http%3A%2F%2Fblocmetrics-klaha1.c9.io%2Fapi%2Fevents
< Date: Thu, 14 May 2015 21:15:55 GMT
< Transfer-Encoding: chunked
< 
* Connection #0 to host blocmetrics-klaha1.c9.io left intact

这是我的 routes.rb

namespace :api, defaults: { format: :json } do
  resources :events, only: [:create]
end

这是 api / events_controller.rb

class API::EventsController < ApplicationController
  skip_before_action :verify_authenticity_token

  def create
    registered_application = RegisteredApplication.find_by(url: request.env['HTTP_ORIGIN'])

    if registered_application.nil?
      render json: "Unregistered application", status: :unprocessable_entity
    end

    @event = registered_application.events.build(event_params)

    if @event.save
      render json: @event, status: :created
    else
      render @event.errors, status: :unprocessable_entity
    end

  end

  private

  def event_params
    params.require(:event).permit(:name)
  end

end

我对 config / initializers / inflections.rb

所做的更改
ActiveSupport::Inflector.inflections(:en) do |inflect|
  inflect.acronym 'API'
end

最后,卷曲命令我正在使用。

curl -v -H "Accept: application/json" -H "Origin: keeblerheaney.net" -H "Content-Type: application/json" -X POST -d '{"name":"foobar"}'  https://blocmetrics-klaha1.c9.io/api/events

我在这里做错了什么? 谢谢你伸出援助之手!

1 个答案:

答案 0 :(得分:3)

您的工作区是公开的吗?可能不是。如果您希望将代码保密,但每个人都可以访问正在运行的服务器,则可以点击“分享”代码。在菜单中,并检查公共&#39;在“应用程序”旁边,它只会使您的运行服务器公开而不会泄露您的来源。