にアクセスしようとしていますhttp://www.example.com:4380/apid/request?method=getXMLTable&name=1&ui=UI&id=12345
。出力を XML として返す必要があります。これはコードです:
<?
$host = "www.example.com";
$path = "/apid/request?method=getXMLTable&name=1&ui=UI&id=12345";
$port = 4380;
$fp = fsockopen($host, $port, $errno, $errstr, 30);
$buffer ="";
if (!$fp) {
echo "ERR!!<br>";
echo "$errstr ($errno)<br />\n";
} else {
$out = "GET ".$path." HTTP/1.1\r\n";
$out .= "Host: ".$host."\r\n";
$out .= "Connection: Close\r\n\r\n";
fwrite($fp, $out);
while (!feof($fp)) {
$buffer .= fgets($fp, 1024);
}
fclose($fp);
}
?>
とにかく、XML出力ではなく、次の応答が得られます。
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Last-Modified: Wed, 02 Apr 2014 16:16:43 GMT
Cache-Control: no-store
Cache-Control: no-cache
Cache-Control: must-revalidate
Cache-Control: pre-check=0
Cache-Control: post-check=0
Cache-Control: max-age=0
Pragma: no-cache
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Content-Type: text/xml
Transfer-Encoding: chunked
Vary: Accept-Encoding
Date: Wed, 02 Apr 2014 16:16:43 GMT
Connection: close 2000 0
提示されたコードのようなページに'www.example.com/path/to/file'
問題なくアクセスできます。ポート(標準の http ではない)またはリクエストで間違いを犯したと思います。すべての手がかりは大歓迎です。
編集:
can't
httpモジュールを使用しています!この場合、ソケットは必須です。以下のコードを試してみましたが、$body には何も表示されません:
list($header, $body) = explode("\n\n", $buffer, 2);
echo http_chunked_decode($body);