send data array (same key values) using php curl

后端 未结 3 1594
失恋的感觉
失恋的感觉 2021-01-23 22:32

I am sending a list of names and emails.

I am trying to create with curl the same functionality as in this form

相关标签:
3条回答
  • 2021-01-23 23:11

    You might be able to use something like this. Do you have a way to make a dump of the data in the Django script?

    CURLOPT_POSTFIELDS     => array(
        array(
                'name' => 'name1',
                'email' => 'name1@email',
             ),
        array(
                'name' => 'name2',
                'email' => 'name2@email',
             )
    )
    
    0 讨论(0)
  • 2021-01-23 23:24

    In PHP, array keys must be unique. The second 'name' overwrites the data in the first 'name' so you would need a slightly different scheme.

    0 讨论(0)
  • 2021-01-23 23:33

    What i finally did was using a string instead of php assoicative array

    $ch = curl_init();
    $curlConfig = array(
    CURLOPT_URL            => "http://url",
    CURLOPT_POST           => true,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POSTFIELDS     => "name=name1&emailname1@email&name=name2&email=name2@email"
    );
    curl_setopt_array($ch, $curlConfig);
    $result = curl_exec($ch);
    print $result;
    curl_close($ch);
    
    0 讨论(0)
提交回复
热议问题