HTTP problem, wrong characters sent (HTTP pro's needed!)



Hey,

I am writing a file that reads in an external file in the web and
prints it out including the response header of the http protocol. I do
this to enable cross domain XMLHttpRequests.
I implemented it via fsockopen, like this:

<?
$url = $_REQUEST['uri']; // take the param as $uri
//... more ...
if ($c = fsockopen($host, $port, $errorNo, $errorStr, 5)) { //
connection
$headers = getallheaders(); // request headers
$h = ($headers['Content-Type'] ==
'application/x-www-form-urlencoded') ? 'POST' : 'GET'; // request
method
$h .= " $path HTTP/1.1\r\nHost: $host\r\n";
foreach ($headers as $name => $content) {
// don't forward user's (and your) cookies to external server!
if ($name == 'Accept')
$h .= 'Accept:
text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*;q=0.5'."\r\n";
elseif ($name == 'Accept-Encoding')
$h .= 'Accept-Encoding: '."\r\n";
elseif ($name != 'Host' && $name != 'Connection' && $name !=
'Cookie')
$h .= $name.': '.$content."\r\n";
}
$h .= 'Connection: closed'."\r\n";
$h .= "\r\n";
// header sent

// post content
if ($_POST) {
$posts = array();
foreach ($_POST as $key => $value)
$posts[] = urlencode($key).'='.urlencode($value);
$h .= implode('&', $posts);
}
fwrite($c, $h);

// read and output results
$header = true;
while (!feof($c)) {
$p = fgets($c);
if ($p == "\r\n")
$header = false;
if ($header) {
if (strpos($p, 'Content-Type') !== false && $html)
header(str_replace('xml', 'html', $p));
else
header(trim($p));
}
else
echo $p;
}
}
fclose($c);
}
else
echo $errorNo.' '.$errorStr;
}
?>

^ Thats the code, test it in Firefox and IE:

http://aka-fotos.de/research/uniajax/php/http.php?uri=http%3A%2F%2Faka-fotos.de%2Fresearch%2Funiajax%2FresponseXml.php

It means that http.php reads the file
http://aka-fotos.de/research/uniajax/responseXml, a simple XML file
that looks like this:

<?xml version="1.0" encoding="utf-8"?><response>hello</response>

Firefox shows the correct source code, exactly the same as above ^, but
IE shows an error (cannot find the page). To get to the bottom auf
things I used Rex Swains HTTP viewer that shows me all headers of a
http request including the body of the page:
http://rexswain.com/httpview.html. If you paste in my adress -
http://aka-fotos.de/research/uniajax/php/http.php?uri=http%3A%2F%2Faka-fotos.de%2Fresearch%2Funiajax%2FresponseXml.php
- and submit the form, you will see that the response body looks like
this:

(CR)(LF)
26·(CR)(LF)
<?xml·version="1.0"·encoding="utf-8"?>(CR)(LF)
1b·(CR)(LF)
<response>hello</response>(LF)
(CR)(LF)
0(CR)(LF)
(CR)(LF)

(CR) and (LF) are control characters, forget them, but I see some
charakters "26" and "1b". This result differs from what Firefox shows,
can somebody say me whats going on there?

I hope somebody can help me!
Thanks,

Andi

.



Relevant Pages

  • Re: HttpWebRequest POST method Expect header bug
    ... At least this way I got the HTTP POST ... > the Expect header, an error status is received and the request also fails. ... > Compact Framework as the System.Net.ServicePointManager.Expect100Continue ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: URLConnection
    ... Wie z.B. eine HttpUrlConnection im Detail implementiert ist, ... Ich hatte ähnliches was du vorhast (Kontrolle über die Header) mit dem ... Apache http client gemacht. ...
    (de.comp.lang.java)
  • Re: HTTP problem, wrong characters sent (HTTP pros needed!)
    ... prints it out including the response header of the http protocol. ... You are attempting to write an HTTP client yourself. ... request, which means you _must_ implement some features as specified in the ... specification to be able to decode the response, ...
    (comp.lang.php)
  • Re: How to parse HTTP time header?
    ... header. ... about how some servers may still send badly format time headers. ... in the standard library for parsing RFC 2616 dates. ... When I faced the problem of parsing HTTP dates, I wrote my own function although this was in an application that was deliberately unforgiving of invalid input and therefore my code makes no allowances for it. ...
    (comp.lang.python)
  • Re: Web page served as application/xhtml+xml
    ... Andreas Prilop wrote: ... Omit the tag and specify the encoding in the HTTP ... I also seem to recall some lack of UTF-8 support in some text ... not even need to explicitly include it in the HTTP header, ...
    (comp.infosystems.www.authoring.html)