【发布时间】:2009-06-10 08:23:30
【问题描述】:
您好,我想在我的 PHP 脚本中发送一些标头,例如
$headers[] = "BATCH_TYPE: XML_SINGLE";
$headers[] = "VENDOR_ID: 56309";
但他们被接收为:
批处理类型 供应商 ID
..不是他们的预期或要求 - 这给我带来了问题。
有人知道为什么或如何排序吗?
谢谢,
<?php
function httpsPost($Url, $xml_data, $headers)
{
// Initialisation
$ch=curl_init();
// Set parameters
curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_URL, $Url);
// Return a variable instead of posting it directly
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERPWD,"username:password");
// Activate the POST method
curl_setopt($ch, CURLOPT_POST, 1) ;
// Request
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_data);
curl_setopt($ch, CURLOPT_TIMEOUT, 999);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
// execute the connexion
$result = curl_exec($ch);
// Close it
curl_close($ch);
return $result;
}
$request_file = "./post_this.xml";
$fh = fopen($request_file, 'r');
$xml_data = fread($fh, filesize($request_file));
fclose($fh);
$url = 'http://www.xhaus.com/headers';
$headers = array();
$headers[] = "Expect:";
$headers[] = "Accept: text/xml";
$headers[] = "BATCH_TYPE: XML_SINGLE";
$headers[] = "BATCH_COUNT: 1";
$headers[] = "VENDOR_ID: 54367";
$Response = httpsPost($url, $xml_data, $headers);
echo $Response;
?>
【问题讨论】:
-
您如何准确地发送标头?使用 header() 命令?目前,您只是将标头添加到数组中,仅此而已。向我们展示该代码,我们可以提供帮助:)
-
如果你改变 $xml_data ="TEST";然后它会起作用你会明白我的意思。
标签: php http-headers http-post