gpt4 book ai didi

php - cURL 使用字符串发布多个值

转载 作者:行者123 更新时间:2023-12-02 06:35:14 25 4
gpt4 key购买 nike

有没有办法按照下面的代码发布具有多个值的字符串?请考虑第三个 postfield $multiple 输出多个值提前致谢

<?php

$ch = curl_init(); //http post to another server

curl_setopt($ch, CURLOPT_URL,"http://www.example.com");

curl_setopt($ch, CURLOPT_POST, 1);

curl_setopt($ch, CURLOPT_POSTFIELDS,"username=$username&password=$password&multiple=$ ");

// receive server response

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$server_output = curl_exec ($ch);

print_r($server_output);

curl_close ($ch);

最佳答案

Can we include your answer on the above code?

<?php

$ch = curl_init(); //http post to another server

curl_setopt($ch, CURLOPT_URL,"http://www.example.com");

curl_setopt($ch, CURLOPT_POST, 1);

$username = 'user1';
$password = 'strongpassword';

$values = array(
'username' => $username,
'password' => $password,
'multiple' => array(
'value1',
'value2',
'value3',
)
);

$params = http_build_query($values);

curl_setopt($ch, CURLOPT_POSTFIELDS,$params);

// receive server response

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$server_output = curl_exec ($ch);

print_r($server_output);

curl_close ($ch);

例如

关于php - cURL 使用字符串发布多个值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21110458/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com