curl posting with header application/x-www-form-urlencoded

后端 未结 3 1789
你的背包
你的背包 2020-12-08 09:55
$post_data=\"dispnumber=567567567&extension=6\";
$url=\"http://xxxxxxxx.xxx/xx/xx\";

I need to post this $post_data using cURL php

3条回答
  •  有刺的猬
    2020-12-08 10:25

    Try something like:

    $post_data="dispnumber=567567567&extension=6";
    $url="http://xxxxxxxx.xxx/xx/xx";
    
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));   
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
    $result = curl_exec($ch);
    
    echo $result;
    

提交回复
热议问题