1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
|
<?php
// proxy http
// auteur: Marc Gauthier
//30/09/2012
// les erreurs dans les log du serveur
// License : http://creativecommons.org/licenses/by-nc-sa/2.0/fr/
// ----------------------------------------------------------
//
// variables globales
$debug= 0;
$debug_html= 0;
$CLEF='hgy47onayrhjpmk3l80utwjx';
$REFERER='localhost';
$sUrl="http://gpp3-wxs.ign.fr/".$CLEF."/geoportail/ols";
$aUrl= @parse_url($sUrl);
$sHeader = "Host: ".$aUrl['host']."\r\n"
. "Referer: ".$REFERER."\r\n";
$data = '<?xml version="1.0" encoding="UTF-8"?>
<XLS
xmlns:xls="http://www.opengis.net/xls"
xmlns:gml="http://www.opengis.net/gml"
xmlns="http://www.opengis.net/xls"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
version="1.2"
xsi:schemaLocation="http://www.opengis.net/xls http://schemas.opengis.net/ols/1.2/olsAll.xsd">
<RequestHeader/>
<Request requestID="1" version="1.2" methodName="LocationUtilityService">
<GeocodeRequest returnFreeForm="false">
<Address countryCode="StreetAddress">
<freeFormAddress>1 rue Marconi 57000 Metz</freeFormAddress>
</Address>
</GeocodeRequest>
</Request>
</XLS>';
$sReq= "POST $sUrl HTTP/1.0\r\n"
. $sHeader
. "Content-Type: text/xml\r\n"
. "Content-length: ".strlen($data)."\r\n"
. "\r\n"
. $data
;
$sReq.= "\r\n";
// envoi de la requête
carp("url:$sUrl");
$host= $aUrl["host"];
$port = '80';
$fp= @fsockopen($host, $port, $errno, $errstr, 5);
if (!$fp) {
confess("fsockopen failed: $errstr ($errno)");
}
carp("sReq:$sReq");
fwrite($fp, $sReq);
// attente de la réponse
$headers= '';
$sReponse= '';
ob_start();
while (!feof($fp)) {
$sReponse.= fread($fp, 4096);
}
fclose ($fp);
$eoh= strpos($sReponse, "\r\n\r\n");
$headers= substr($sReponse, 0, $eoh);
$sReponse= substr($sReponse, $eoh+4);
$Hs= preg_split('/(?:\r\n|\n)/', $headers);
carp("Hs=[".count($Hs)."]");
for ($i= 0, $l= count($Hs); $i<$l; $i++) {
if (preg_match('/^Content-Length/i', $Hs[$i])) {
continue;
}
if (preg_match('/^Transfer-Encoding: chunked/i', $Hs[$i])) {
// Transfer-Encoding: chunked
carp("chunked response");
$sReponse= unchunck($sReponse);
continue;
}
#carp("header=[$Hs[$i]]");
header($Hs[$i]);
}
header("Content-Length: ".strlen($sReponse));
print $sReponse;
//
// écriture d'un message de log
function carp($msg) {
global $debug;
global $debug_html;
if ($debug) {
if ($debug_html) {
print "__FILE__.:$msg.<br>\n";
}
error_log(__FILE__.": $msg", 0);
}
}
//
// écriture d'un message de log et erreur http
function confess($msg) {
carp($msg);
header("HTTP/1.0 500 $msg");
exit;
}
?> |
Partager