【发布时间】:2011-09-20 12:24:14
【问题描述】:
好的,我想提出一个 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 脚本文件中有 session_start() 吗?
-
是的,我做 session_set_cookie_params(0, '/'); session_start();