开发者

HTTP GET request via fsockopen() returning extraneous characters

I'm using fsockopen() to request a value from a page on another server. The value returned is just a sing开发者_如何学Cle word (ex. "French"). This works fine when I test on localhost (MAMP), making the request to the remote server. However when I test server-to-server I end up with extra characters, such as:

6%0D%0AFrench%0D%0A0%0D%0A%0D%0A or 7%0D%0AEnglish%0D%0A0%0D%0A%0D%0A

I'm using the http_request() function that's shown here. The only change I made was to increase the timeout. I'm calling it using:

$thelanguage = http_request('GET', $domain, 80, $path);

I've tested this to and from multiple servers, and the extra characters show up when I make the request from anywhere except localhost.

I'm kind of at a loss as to how to proceed. It appears that the 6 or 7 at the beginning of the strings returned are a character count, but I have no idea where that's coming from. Any help would be greatly appreciated.


It appears that the 6 or 7 at the beginning of the strings returned are a character count,

Yup! You're seeing chunked transfer encoding: data length, CRLF, the data, then two more CRLF pairs. I believe that last CRLF means that it was the last chunk.

You probably want to use a more well-developed, well-tested, full-featured HTTP request mechanism, like the usually-built-in curl extension or PEAR's HTTP_Request2.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜