【问题标题】:Convert Curl to Unirest将 Curl 转换为 Unirest
【发布时间】:2016-05-20 15:39:55
【问题描述】:

这是来自 Stripe API curl 方法的 curl 请求:

curl https://api.stripe.com/v1/accounts \
   -u sk_test_**********: \
   -d managed=false \
   -d country=US \
   -d email="bob@example.com"

现在我有这个唯一的代码:

<?php Unirest\Request::auth(Config::get("stripe.secret.api_key"), '');

        $headers = array(
            "Content-Type" => "application/json"
        );
        $body    = array(  
           "managed" => $_managed,
           "country" => $_country,
           "email"   => $_email,
        );
        $response = Unirest\Request::post("https://api.stripe.com/v1/accounts", $headers, $body);
        return array(
            'status'  => 'success',
            'message' => $response
        ); ?>

条带返回方法错误。我认为它是 curl 中的 -u 参数。

【问题讨论】:

    标签: php curl unirest


    【解决方案1】:

    我对@9​​87654322@ 不太了解。当您遇到-u 标头的问题时,您可以在 url 中使用授权参数,如下所示。

    https://sk_test_RxRTXF1CDHuRw3ZUdynxnG6P:@api.stripe.com/v1/accounts
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    

    【讨论】:

    • 从您的代码中删除标题 "Content-Type" =&gt; "application/json"。你没有在那里传递 json。
    • 但是-u sk_test_ASX21312FCA是什么参数?
    • 试过这个https://sk_test_RxRTXF1CDHuRw3ZUdynxnG6P:@api.stripe.com/v1/accounts没用
    • 您的 Unirest(或 curl)可能未配置为 ssl。我没有在 Unirest 上看到任何关于 ssl 的文档,除了这个:github.com/Mashape/unirest-php#ssl-validation 并且禁用验证不是一个好主意。
    猜你喜欢
    • 2018-05-23
    • 2019-12-18
    • 2017-06-05
    • 2016-01-08
    • 2018-03-28
    • 2021-03-27
    • 2019-11-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多