Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 将此curl行转换为Rails Post请求并返回JSON响应_Ruby On Rails_Json_Post_Request_Response - Fatal编程技术网

Ruby on rails 将此curl行转换为Rails Post请求并返回JSON响应

Ruby on rails 将此curl行转换为Rails Post请求并返回JSON响应,ruby-on-rails,json,post,request,response,Ruby On Rails,Json,Post,Request,Response,我已经发布了一些与此相关的问题,但我仍然有点迷失在实现中 基本上,我需要将这一行从Venmo API转换为付款: curl https://api.venmo.com/v1/payments -d access_token=4e4sw1111111111t8an8dektggtcbb45 -d email="someemail@gmail.com" -d amount=5 -d note="Delivery." 以POST请求表单/格式进入我的Rails站点 我现在对表格有以下看法: <

我已经发布了一些与此相关的问题,但我仍然有点迷失在实现中

基本上,我需要将这一行从Venmo API转换为付款:

curl https://api.venmo.com/v1/payments -d access_token=4e4sw1111111111t8an8dektggtcbb45 -d email="someemail@gmail.com" -d amount=5 -d note="Delivery."
以POST请求表单/格式进入我的Rails站点

我现在对表格有以下看法:

<!-- Venmo box -->
                    <div class="box box-warning">
                        <div class="box-header">
                            <%= form_tag ('/make_payment_path') do %>
                            <%= hidden_field_tag "access_token", @access_token %>
                          <h3 class="box-title">Pay Bill using Venmo Account</h3>
                            <div id="payment_note_input">
                            <%= text_field_tag "payment_note", nil, class:"form-control", placeholder: "add a note to your payment" %>
                            </div>
                            <div id="payment_target_input">
                                <%= text_field_tag "payment_target", nil, class:"form-control", placeholder: "pay an email address" %>
                            </div>
                            <div id="payment_amount_input">
                                <%= text_field_tag "payment_amount", nil, class:"form-control", placeholder: "enter the payment amount!"%>
                            </div>
                                </br>
                        <%= submit_tag "Make payment", class: "btn btn-danger" %>
                        <% end %>
                    </div>

有人能帮我指出正确的方向吗?一旦通过Venmo处理此POST请求,它将返回一个JSON响应,如图所示。

您没有指定错误消息是什么。:-)

我运行了您的代码,response.body显示“400普通HTTP请求被发送到HTTPS端口”

看起来您需要使用以下命令强制SSL:

http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_PEER 
示例:

http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
request = Net::HTTP::Post.new(uri.request_uri)
新代码获得json响应:

{"error": {"message": "You did not pass a valid OAuth access token.", "code": 261}}
假设添加正确的访问令牌将解决此问题


作为旁注,您可能还希望将控制器代码移动到模型中

我对这部分代码感到困惑:
,因为当我测试它时,它需要一个用于支付路径的路径。这个表单应该创建一个路由吗?是的,你需要一个路由。routes.rb只是一个交通调度员,它会指引您找到正确的调度员。在这种情况下,如果没有路由,Rails不知道将/make_payment_路径发送到仪表板控制器的make_payment_path操作。假设您的控制器名为Dashboard,则此路径应该可以完成此操作:发布“支付路径”=>“Dashboard支付路径”更多信息:好的,我添加了一个正确的路径,如您前面所述,现在,通过在仪表板控制器中的make_payment路径操作的底部添加
redirect_to:action=>:confirm_payment
使其工作。现在如何从Venmo API呈现JSON响应?
render JSON:response.body
是我在这里寻找的内容。我想剩下的我都有了。谢谢你的帮助!
{"error": {"message": "You did not pass a valid OAuth access token.", "code": 261}}