php - 将 Curl 转换为 Unirest

标签 php curl unirest

这是来自 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"

现在我有这个 unirest 代码:

<?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
        ); ?>

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

最佳答案

我对 Unirest 了解不多。当您遇到 -u header 问题时,您可以在 url 中使用授权参数,如下所示。

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

关于php - 将 Curl 转换为 Unirest,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35312625/

相关文章:

php cURL 问题

php - 通过 HTTP 从远程服务器复制图像

perl - 使用 curl 和 perl 代理

python - 在 Unirest 中使用代理

java.lang.NoSuchFieldError : org. apache.http.message.BasicLineFormatter.INSTANCE 来自 Java 应用程序中的 Mashape Unirest

具有多种模式的 php preg_match

php - 使用 UTF-8 时出现 CSS/PHP 验证错误?

php - 使用 shell_exec 发送电子邮件失败

c# - 如何将 JSON 响应映射到自定义类对象

php - 如何找到所有东西而不是一个词