2009-06-10 19 views
0

嗨,我是特灵在我的PHP脚本发送一些头如HTTP邮政头,从接收到的不同是什么东西被发送到

$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; 

?> 
+0

你是如何真正发送标题的?使用header()命令?目前,您只是将标题添加到数组中,没有别的。 给我们看看代码,我们可以帮助:) – Jrgns 2009-06-10 10:06:36

+0

好吧,现在遗憾代码 – thegunner 2009-06-10 10:22:17

+0

如果更改$ xml_data =“TEST”;那么它会工作,你会明白我的意思。 – thegunner 2009-06-10 10:27:10

回答

0

与本公司外部服务器的作战经过一周,他们实际上给了我错误的标题 - 德哦!

0

你是如何检查这些标题?我只是试着自己用下面的代码: -

<?php 

header("BATCH_TYPE: XML_SINGLE"); 

而且将得到以下内容: -

HTTP/1.1 200 OK 
Date: Wed, 10 Jun 2009 08:56:54 GMT 
Server: Apache/2.2.11 (Ubuntu) PHP/5.2.6-3ubuntu4.1 with Suhosin-Patch 
X-Powered-By: PHP/5.2.6-3ubuntu4.1 
BATCH_TYPE: XML_SINGLE 
Vary: Accept-Encoding 
Content-Length: 0 
Content-Type: text/html 
0

使用fsockopen()和读/写手动您需要什么。我不确定你的CURL或者smth的实现。否则像代理不会更改您的标题。如果你想做的事情肯定 - 只是自己做;)。其实它很容易创建HTTP请求,并将其写入打开插座......

$req = "POST $url HTTP/1.0\n"; 
$headers[] = 'VENDOR_ID: 1234'; 
$headers[] = 'MY_OTHER_HEADER: xxxxx'; 
$req .= implode("\n", $headers); 
$req .= "\n\n" . $request_body; 

$sock = fsockopen($host, 80, $errno, $errstr, $timeout); 
fwrite($sock, $req, strlen($req)); 

$return = ''; 
do 
{ 
    $return .= fread($sock, 512); 
} while (!feof($sock)); 

fclose($sock); 

不知道,但在我看来,那水木清华。像这样的已经在某个地方做梨...

0

更改下面的代码:

curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 

要这样:

foreach($headers as $header) 
    curl_setopt($ch, CURLOPT_HTTPHEADER, $header); 
相关问题