我已经设置了一个 API,可以将信息发送到端点以进行背景检查。我遇到的问题是 excon 正在开发中,但不会在生产模式下发送 POST API 请求。我的 API 请求正文位于启动进程的 link_to 的控制器操作内。我的 rails 日志显示它响应为 html 并发送授权令牌。唯一需要的 Authorization 标头是 API 密钥本身。 如何让 excon 在生产环境中发送正确的 HTTP 请求?
forms_controller.rb
class FormsController.rb
...
def run_candidate_background_check
@form = Form.find(params[:id])
@form_info = @form.info
@form_credential = @form.credential
respond_to do |format|
if @form_info.first_name.present? && ...
excon.post("https://api.backgroundchecker.com/v1/Report",body: {
"Candidate": {
"FirstName": "#{@form_info.first_name}",....
"Address": "#{@form_info.full_address}"
},"Offer": {
"Products": [
"PROD_ID"
]
},"RequestOptions": {
"SendPurchaseReceipt": true
}
}.to_json,headers: {"Content-Type" => "application/json",'Authorization' => "ApiKey 444444444"}
format.html {redirect_to home_path,notice: "The background check was successfully started"
else
format.html {redirect_to forms_path,notice: "The background check wasn't successfully started,check that all inputs are completed"
end
end
routes.rb
resources :forms do
post :run_candidate_background_check
end
index.html.erb
@forms.each do |form|
<%= form.info.first_name %>
<%= link_to form_run_candidate_background_check_path(form_id: form.id,id: form.id),method: :post,class: 'btn btn-primary' do %>
Start background check
<% end %>
end