How convert linux command CURL to PHP

前端 未结 3 1188
再見小時候
再見小時候 2021-01-24 08:22

I want to convert this linux command console to PHP code, to send data via curl,

curl -X POST -d \'data[][street]=1\' link.....

Thanks!!

3条回答
  •  失恋的感觉
    2021-01-24 09:02

    $fields = 2;
    $fields_as_string = "key=value&key2=value"    
    
    //open the curl connection
    $ch = curl_init();
    
    //set the url, number of POST vars, POST data
    curl_setopt($ch,CURLOPT_URL, $url);
    // set the number of post fields
    curl_setopt($ch,CURLOPT_POST, $fields);
    // set the fields
    curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_as_string);
    
    //execute post
    $result = curl_exec($ch);
    
    //close connection
    curl_close($ch);
    

    Don't forget to make sure you've enabled the curl php extension.

提交回复
热议问题