将帖子卷曲到远程服务器

Dja*_*Dev 0 php curl

我对curl的概念和想法并不陌生,我想将波纹管值发布到远程服务器https://example.com/test/token。值是client_secret = sk_test_dndkFknKdtMLhv0eA8OdcgW1,代码= GH_Dgl12,grant_type = dsfgsdK。我怎样才能做到这一点?

May*_*Roy 5

使用参数进行curl发布的简单示例:

<?php
//
// A very simple PHP example that sends a HTTP POST to a remote site
//

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL,"http://www.mysite.com/tester.phtml");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,
        "client_secret=sk_test_dndkFknKdtMLhv0eA8OdcgW1, code=GH_Dgl12, grant_type=dsfgsdK");

// receive server response ...
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$server_output = curl_exec ($ch);

curl_close ($ch);

// further processing ....
if ($server_output == "OK") { ... } else { ... }

?>
Run Code Online (Sandbox Code Playgroud)

选项CURLOPT_RETURNTRANSFER将使curl_exec()返回响应,以便您也可以捕获它。