2009-06-10 53 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); 
相關問題