cURL not working with POST data

前端 未结 3 1450
感情败类
感情败类 2021-01-27 20:50

I am trying to debug this, but I\'ve had no luck. Am I sending the POST data correctly?

if (isset($_POST[\'chrisBox\'])) {

$curl = curl_init();
curl_setopt($cur         


        
3条回答
  •  心在旅途
    2021-01-27 21:31

    The parameters sent in a $_POST request need to be in the form of -

    key=value&foo=bar
    

    You can use PHP's http-build-query function for this. It'll create a query string from an array.

    curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($_POST));
    

    If you only want to pass one parameter, you'll still need to wrap it in an array or object.

    $params = array(
      'stack'=>'overflow'
    );
    
    http_build_query($params);     // stack=overflow
    

提交回复
热议问题