2 回答

TA貢獻(xiàn)1815條經(jīng)驗(yàn) 獲得超10個(gè)贊
2019 年 11 月 30 日更新:
請(qǐng)?jiān)囋嚕?/p>
$data = array(
'amount' => '100',
'currency' => 'DKK',
'merchant' => 'INSERT_YOUR_MERCHANT_ID',
'orderId' => 'Order_ID-123',
'textreply' => 'true',
'ticket' => '1234567890'
);
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://postman-echo.com/post",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => false,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS =>$data,
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
///////////////////////////////////////// /////////////////////////
要調(diào)試 PHP curl,請(qǐng)運(yùn)行并提供反饋:
$headers = array(
"Content-Type: application/x-www-form-urlencoded"
);
$data = array(
'amount' => '100',
'currency' => 'DKK',
'merchant' => 'INSERT_YOUR_MERCHANT_ID',
'orderId' => 'Order_ID-123',
'textreply' => 'true',
'ticket' => '1234567890'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://postman-echo.com/post");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_TIMEOUT_MS, 1000);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
curl_setopt($ch, CURLOPT_ENCODING , "gzip");
curl_setopt($ch, CURLOPT_USERAGENT,'php');
curl_setopt($ch, CURLOPT_HTTPHEADER,$headers);
$info = curl_getinfo($ch);
$result = curl_exec($ch);
print_r($info );
echo "</br>";
print_r($result );

TA貢獻(xiàn)1796條經(jīng)驗(yàn) 獲得超7個(gè)贊
您可以使用Guzzle HTTP Client輕松完成此操作。
$client = new GuzzleHttp\Client();
$response = $client->post('https://postman-echo.com/post', [
'form_params' => [
'amount' => '100',
'currency' => 'DKK',
'merchant' => 'INSERT_YOUR_MERCHANT_ID',
'orderId' => 'Order_ID-123',
'textreply' => 'true',
'ticket' => '1234567890'
]
]);
然后,您可以根據(jù)需要使用響應(yīng)。
- 2 回答
- 0 關(guān)注
- 120 瀏覽
添加回答
舉報(bào)