Pregunta

HI Estoy Tring para enviar algunas cabeceras en mi script PHP como

$headers[] = "BATCH_TYPE: XML_SINGLE"; 
$headers[] = "VENDOR_ID: 56309";

Pero ellos están siendo recibidos como:

Batch-Type Vendor-ID

.. no ya que estaban destinados o necesarios -. Que está causándome problemas

Alguien sabe por qué o cómo ordenar?

Gracias,

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

?>
¿Fue útil?

Solución 4

Después de una semana de luchar con la compañía de este servidor externo, que eran de hecho darme las cabeceras erróneas - D'oh

Otros consejos

¿Cómo estás mirando estas cabeceras? Sólo me he probado con el siguiente código: -

<?php

header("BATCH_TYPE: XML_SINGLE");

y volvió a lo siguiente: -

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

fsockopen () y escribir / leer manualmente cualquier cosa que necesitar. No estoy seguro de si su aplicación de Curl o algo bajo. más como proxy no cambie sus cabeceras. Si quieres hacer algo bueno para asegurarse - hazlo tu mismo;). De hecho, es tan fácil crear petición de HTTP y escribirla en socket abierto ...

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

No estoy seguro, pero me parece que algo bajo. como esto ya se ha hecho en algún lugar de PERA ...

Cambiar el código siguiente:

curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

A esto:

foreach($headers as $header)
    curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top