"HTTP 302 Moved Temporarily" 当 CURL 在 Cloud9 上使用 Rails
"HTTP 302 Moved Temporarily" when CURL on Cloud9 using Rails
我有一个简单的应用程序,可以接受创建事件的请求。它应该使用 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 命令。
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
我在这里做错了什么?
谢谢你帮我一把!
你的工作空间是public吗?可能不会。如果您想将您的代码保密,但每个人都可以访问您的 运行 服务器,您可以点击菜单中的 'Share',然后选中 [=14= 旁边的 'public' ],这只会使您的 运行 服务器 public 而不会暴露您的来源。
我有一个简单的应用程序,可以接受创建事件的请求。它应该使用 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 命令。
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
我在这里做错了什么? 谢谢你帮我一把!
你的工作空间是public吗?可能不会。如果您想将您的代码保密,但每个人都可以访问您的 运行 服务器,您可以点击菜单中的 'Share',然后选中 [=14= 旁边的 'public' ],这只会使您的 运行 服务器 public 而不会暴露您的来源。