PHP curl Post请求和Get请求~

时间:2024-11-26 10:06:43

//获取的参数
$api_key = '8a82d53a57b06c1d835d129f7e43d49c';

$orderNum = pdo_fetch('select ddlm_order_no from'.tablename('ewei_shop_order') . 'where id=' . $_GPC['id']);
$status = 5;
$remarks = $_GPC['content'];

// 将需要传输的参数 放入一个数组
$ddlminfo = ['apikey' => $api_key,'orderNum' => $orderNum['ddlm_order_no'] , 'order_status' => $status, 'remarks' => $remarks];
//需要请求的url

$url = 'http://39.105.192.179/api/Supplygoods/updateOrderStatus';

初始化init
$curl = curl_init();

//设置抓取的url

curl_setopt($curl, CURLOPT_URL,$url );

//设置头文件的信息作为数据流输出

curl_setopt($curl, CURLOPT_HEADER, 0);

//设置获取的信息以文件流的形式返回,而不是直接输出

curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

//设置post方式提交
curl_setopt($curl, CURLOPT_POST, 1);

//设置post方式提交
curl_setopt($curl, CURLOPT_POSTFIELDS, $ddlminfo);

//执行命令

$data1 = curl_exec($curl);

//关闭url请求
curl_close($curl);

// 将订单返回值使用json格式转换
$result = json_decode($data1,true);

PHP  curl Post请求和Get请求~

CURL的GET请求方式的写法~

$url表示请求的路径~ 传参数可直接拼接在路径之后

function httpGet($url) {
$curl = curl_init();
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_TIMEOUT, 500);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_URL, $url);

$res = curl_exec($curl);
curl_close($curl);

return $res;
}

PHP  curl Post请求和Get请求~