好的,所以我想要一个卷曲请求。
$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'));
}
我没有得到我设置的数组。这两个文件位于同一台服务器btw
上答案 0 :(得分:3)
尝试:
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);
答案 1 :(得分:0)
试试这个
$post = "";
$amp = "";
foreach($_SESSION['cart'] as $key => $value) {
$post .= $amp . $key . "=" . urlencode($value);
$amp = "&";
}
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
答案 2 :(得分:0)
尝试使用php序列化和反序列化函数