我遇到了一个问题,我的POST请求Excon gem没有在生产中发送,但在开发中工作完美。在我的日志中,它显示处理serviceformscontroller# run_background_check为HTML。我不知道为什么会这样……它上周工作得很好。现在突然之间,没有任何请求从生产服务器发出……它显示了正在发生的操作,但API端点从未接收到POST。我将该网站添加到我的CORS配置中作为白名单域。这对改善结果没有任何作用。
service_forms_controller.rb
class ServiceFormsController < ApplicationController
@service_form = ServiceForm.find(params[:id])
@service_info = @service_form.info
if @service_info.first_name.present? && @service_info.last_name.present? && @service_info.ssn.present? && @service_info.address.present? && @service_info.email.present?
@report_builder = GoodHire.new
if Rails.env.production?
@report_builder.create_report_for_candidate(@service_info.first_name, @service_info.last_name, @service_info.ssn, @service_info.address, @service_info.email)
# other mandatory fields added to this call
end
redirect_to service_forms_path, notice: "You've submitted the candidate for a background check"
else
redirect_to service_forms_path, notice: "The candidate doesn't have all fields completed"
end
good_hire.rb
class GoodHire
API_KEY_PROD = 'ZZzazzee'
include RestClient
include Excon
def create_report_for_candidate(first_name, last_name, email, ssn, address, city, state, zip, work_histories =[].....,api_key = API_KEY_PROD)
begin
Excon.post("https://api.goodhire.com/v1/Report", body: {
"Candidate": {
"FirstName": "#{first_name}"
....
...
},
"Offer": {
"Products": [
"....ID"
]
},
"RequestOptions": {
"SendPurchaseReceipt": true
}
}.to_json, headers: {"Content-Type" => "application/json", "Authorization" => "ApiKey #{api_key}"})
rescue Excon::Errors => e
puts "RESPONSE ERROR #{e.response}"
end
end
服务器开发日志
Started POST "/service_forms/7/run_candidate_bckground_check?id=7" for 127.0.0.1
Processing by ServiceFormsController#run_candidate_background_check as HTML
Parameters: {"authenticity_token" => "zregegegergergergegegege", "id" => "7", "service_form_id"=> "7"}
app/controllers/service_forms_controller.rb: in `run_candidate_background_check'
Redirected to https://127.0.0.1:3000/service_forms
Completed 302 Found in 4359ms
Started GET "/service_forms" for 127.0.0.1
initate_background_check.html.erb
<body>
<%= button_to service_form_run_candidate_background_check(service_form_id: @service_form.id, id: @service_form.id), method: :post, class: 'bttn-simple bttn-sm bttn-primary'do %>
Start Background Check
<% end %>
</body>
API验证导致API请求失败