gpt4 book ai didi

php - 如何将数组添加到 url 或发送 post 数组?

转载 作者:行者123 更新时间:2023-12-04 06:21:57 25 4
gpt4 key购买 nike

好的,所以我有一个我正在尝试提出的 curl 请求。

$ch = curl_init();
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "http://someurl.com/shop_pos/index.php?route=module/cart/ajax_get_all_products");

// Do a POST
$items =
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $_SESSION['cart']);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_VERBOSE, true);
$result = curl_exec($ch);
curl_close($ch);
echo $result;

内容或 $_SESSION['cart']
Array
(
[155] => 1
[78] => 1
)

我需要将此数据作为发布数据或获取变量发送...任何建议

关于捕捉功能
public function ajax_get_all_products(){
$this->language->load('module/cart');
$all_products = $this->cart->getProducts();
$data_returned = json_encode($all_products);
echo "<pre>".print_r($_REQUEST, true)."</pre>";
echo "<pre>".print_r($_POST, true)."</pre>";
$this->response->setOutput($data_returned, $this->config->get('config_compression'));
}

我没有得到我设置的数组。顺便说一下,这两个文件在同一台服务器上

最佳答案

尝试:

curl_setopt($ch, CURLOPT_POSTFIELDS, array('items' => $_SESSION['cart']));

尝试这个:
$post_data = http_build_query(array('items' => $_SESSION['cart']));
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);

关于php - 如何将数组添加到 url 或发送 post 数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6442558/

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