php curl: I need a simple post request and retrival of page example

前端 未结 8 1091
走了就别回头了
走了就别回头了 2020-11-27 17:18

I would like to know how to send a post request in curl and get the response page.

8条回答
  •  旧时难觅i
    2020-11-27 18:09

    Using JSON DATA with CURL

    client.php

        'abc','password'=>'123'];
    $data = json_encode($data);
    
    $ch = curl_init();
    $curlConfig = array(
        CURLOPT_URL            => $url,
        CURLOPT_HTTPHEADER     => array('Content-Type: application/json'),
        CURLOPT_POST           => true,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_POSTFIELDS     => $data
    );
    curl_setopt_array($ch, $curlConfig);
    $result = curl_exec($ch);
    curl_close($ch);
    echo $result;  //here you get result like: username: abc and password: 123
    ?>
    

    curl_server.php

        
    

提交回复
热议问题