Post multidimensional array using CURL and get the result on server

后端 未结 3 1206
情书的邮戳
情书的邮戳 2020-12-11 03:23

I am sending data from my local machine to server using CURL. And the data is multidimensional array.

Array
(
[0] => stdClass Object
    (
           


        
3条回答
  •  悲哀的现实
    2020-12-11 03:36

    cURL can only accept a simple key-value paired array where the values are strings, it can't take an array like yours which is an array of objects. However it does accept a ready made string of POST data, so you can build the string yourself and pass that instead:

    $str = http_build_query($array);
    
    ...
    
    curl_setopt($ch, CURLOPT_POSTFIELDS, $str);
    

    A print_r($_POST) on the receiving end will show:

    Array
    (
        [0] => Array
            (
                [id] => 1
            )
    
        [1] => Array
            (
                [id] => 0
            )
    
        [2] => Array
            (
                [id] => 11
            )
    
    )
    

提交回复
热议问题