我正在尝试使用cURL发送HTML表单POST数据,但似乎响应始终为空。我首先将所有POST数据保存在一个数组中,然后使用implode函数。当我回显出implode字符串时,它会返回值,但是在cURL之后它只是空的。
这是设置。我在提交表格后调用此函数
$this->OCIcURL($this->request->post);
public function OCIcURL($post) {
$data_oci = array();
$items_oci = array();
$counter = 0;
$data_oci['~caller'] = 'CTLG';
foreach ($post['item'] as $key => $value)
{
$counter++;
$data_oci['NEW_ITEM-DESCRIPTION[' . $counter . ']'] = $value;
$data_oci['NEW_ITEM-MATNR[' . $counter . ']'] = "";
$data_oci['NEW_ITEM-QUANTITY[' . $counter . ']'] = $post['amount'][$counter];
$data_oci['NEW_ITEM-UNIT[' . $counter . ']'] = "";
$data_oci['NEW_ITEM-PRICE[' . $counter . ']'] = $post['price'][$counter];
$data_oci['NEW_ITEM-CURRENCY[' . $counter . ']'] = $this->session->data['currency'];
$data_oci['NEW_ITEM-PRICEUNIT[' . $counter . ']'] = 1;
$data_oci['NEW_ITEM-LEADTIME[' . $counter . ']'] = "";
$data_oci['NEW_ITEM-VENDOR[' . $counter . ']'] = "";
$data_oci['NEW_ITEM-VENDORMAT[' . $counter . ']'] = "";
$data_oci['NEW_ITEM-MANUFACTCODE[' . $counter . ']'] = "";
$data_oci['NEW_ITEM-MANUFACTMAT[' . $counter . ']'] = "";
$data_oci['NEW_ITEM-MATGROUP[' . $counter . ']'] = "";
$data_oci['NEW_ITEM-SERVICE[' . $counter . ']'] = "";
$data_oci['NEW_ITEM-CONTRACT[' . $counter . ']'] = "";
$data_oci['NEW_ITEM-CONTRACT_ITEM[' . $counter . ']'] = "";
$data_oci['NEW_ITEM-EXT_QUOTE_ID[' . $counter . ']'] = "";
$data_oci['NEW_ITEM-EXT_QUOTE_ITEM[' . $counter . ']'] = "";
$data_oci['NEW_ITEM-EXT_PRODUCT_ID[' . $counter . ']'] = "";
$data_oci['NEW_ITEM-ATTACHMENT[' . $counter . ']'] = "";
$data_oci['NEW_ITEM-ATTACHMENT_TITLE[' . $counter . ']'] = "";
$data_oci['NEW_ITEM-ATTACHMENT_PURPOSE[' . $counter . ']'] = "";
$data_oci['NEW_ITEM-EXT_SCHEMA_TYPE[' . $counter . ']'] = "";
$data_oci['NEW_ITEM-EXT_CATEGORY_ID[' . $counter . ']'] = "";
$data_oci['NEW_ITEM-CUST_FIELD1[' . $counter . ']'] = 21;
$data_oci['NEW_ITEM-PARENT_ID[' . $counter . ']'] = "";
$data_oci['NEW_ITEM-ITEM_TYPE[' . $counter . ']'] = "";
}
foreach ($data_oci as $key => $value)
{
$items_oci[] = $key . '=' . $value;
}
$string_oci = implode('&', $items_oci);
如果我回应$string_oci
,我会得到一个结果。在此之后,我使用cURL将字符串发送到链接。
$url = "http://localhost/test.php";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $string_oci);
curl_setopt($ch, CURLOPT_RETURNTRANSFER , 1); // RETURN THE CONTENTS OF THE CALL
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
$response = curl_exec($ch);
var_dump($response);
}
var_dump始终为空,返回string(0) ""
。我也在现场网站上试过这个,结果相同。
我使用这段代码来查看任何错误,但似乎根本没有任何错误,但var_dump
始终为空。
if (curl_exec($ch) === FALSE)
{
print_r(curl_getinfo($ch));
die("Curl error: " . curl_error($ch));
}
else
{
curl_close($ch);
}
答案 0 :(得分:0)
$endpoint="http://localhost/test3.php";
$session = curl_init($endpoint);
curl_setopt($session, CURLOPT_POST, true);
curl_setopt($session, CURLOPT_HEADER, true);
curl_setopt($session, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($session, CURLOPT_POSTFIELDS, $string_oci);
curl_setopt($session, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($session);
var_dump($response);
curl_close($session);
你的curl请求中需要一个标题,你的curl_init需要一个url。试试我附上的代码。