【发布时间】:2014-06-16 10:52:25
【问题描述】:
我正在尝试通过 cURL 发送 POST 数据,但它没有发送数据,但是当我将它们作为它发送的 GET 变量发送时,有人知道问题可能是什么吗?
curl_setopt_array($ch, array(
CURLOPT_URL => "local.new.api.test.com/authenticate/"
));
$data = array(
'username' => 'test',
'password' => 'test'
);
$data_string = json_encode($data);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
【问题讨论】:
-
是完整的代码吗?请求的 URL 在哪里?
-
@hindmost 嗨,我没有发布它,因为我使用的是本地虚拟主机,我已经编辑了原始帖子
-
刚刚想通了。我的虚拟主机正在重定向请求,因此我必须设置以下选项以使其转发发布数据: curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_POSTREDIR, 3);