Bug #15279 Updated: RETURNTRANSFER and CUSTOMREQUST do not play well together
| From: | robert at gonkgonk dot com | Date: | Sat, 09 Feb 2002 01:54:51 +0000 |
| Subject: | Bug #15279 Updated: RETURNTRANSFER and CUSTOMREQUST do not play well together | ||
| References: | 1 | Groups: | php.dev php.doc |
| Request: | Send a blank email to php-dev+get-79786@lists.php.net to get a copy of this message | ||
ID: 15279
Updated by: robert@gonkgonk.com
Reported By: robert@gonkgonk.com
-Status: Feedback
+Status: Open
Bug Type: Documentation problem
Operating System: Linux
PHP Version: 4.1.1
Assigned To: torben
New Comment:
Yes, actually, that is what I would have expected it to return, since
my machine doesn't have any index file in the root director. Only, I
would have expected it in all three cases, but I guess you caught that
:)
Anyhow, it appears you are right, and that I am misusing the
CUSTOMREQUEST option. Your example executed as expected. I looked at
the curl_easy_setopt manpage and confirmed this (why I had not caught
this before from the man page is a good question).
The strange thing is that I have been using CUSTOMREQUEST on a machine
running 4.0.6 to post XML in a fashion such as this:
$xml = '';
$xml .= "POST /somepath HTTP/1.1\r\n";
$xml .= "Host: somehost\r\n";
$xml .= "Content-Type: text/xml\r\n";
$xml .= "\r\n"
$xml .= $xmldoc;
...
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $request);
...
Anyhow, I feel really silly now; I should have seen this answer long
before now. But at least I know why I haven't been able to duplicate
the behavior of the one machine that is working, though why it is
working is an interesting question.
Thanks,
robert
Previous Comments:
------------------------------------------------------------------------
[2002-02-08 17:08:05] torben@php.net
Scratch the first paragraph of my last post. :)
Torben
------------------------------------------------------------------------
[2002-02-08 17:01:43] torben@php.net
Well, in the first place, the results below show that it
did in fact work for you, but that your server isn't set
up to provide a directory listing of the root dir and
also doesn't have an index file there.
A bit more research shows that valid values for
CURLOPT_CUSTOMREQUEST are things like 'GET', 'HEAD',
'DELETE', and so on. You should not enter the whole request
line, and you should not enter any newlines/carriage returns.
If the following script works for you, I will reclassify
this as a documentation problem.
<?php
error_reporting(E_ALL);
$c = curl_init();
$request = "GET";
curl_setopt($c, CURLOPT_URL,
'http://localhost:8080/testfiles/phptest.php');
curl_setopt($c, CURLOPT_CUSTOMREQUEST, $request);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
echo trim(curl_exec($c));
curl_close($c);
?>
Torben
------------------------------------------------------------------------
[2002-02-08 16:42:03] robert@gonkgonk.com
Sure. Here are some very simple runs and results. I do not think that
any request will ever work.
----- START
----- SRC
<?
$curl = curl_init();
$request = 'GET' . "\r\n";
curl_setopt($curl, CURLOPT_URL, 'http://localhost:8080/');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $request);
$data = curl_exec ($curl);
echo $data . "\r\n";
?>
----- RESULT
[BLANK]
----- END
----- START
----- SRC
<?
$curl = curl_init();
$request = 'GET' . "\r\n";
curl_setopt($curl, CURLOPT_URL, 'http://localhost:8080/');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec ($curl);
echo $data . "\r\n";
?>
----- RESULT
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<HTML><HEAD>
<TITLE>403 Forbidden</TITLE>
</HEAD><BODY>
<H1>Forbidden</H1>
You don't have permission to access /
on this server.<P>
<HR>
<ADDRESS>Apache/1.3.22 Server at 127.0.0.1 Port 8080</ADDRESS>
</BODY></HTML>
----- END
----- START
----- SRC
<?
$curl = curl_init();
$request = 'GET' . "\r\n";
curl_setopt($curl, CURLOPT_URL, 'http://localhost:8080/');
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $request);
$data = curl_exec ($curl);
?>
----- RESULT
<HTML><HEAD>
<TITLE>403 Forbidden</TITLE>
</HEAD><BODY>
<H1>Forbidden</H1>
You don't have permission to access /
on this server.<P>
<HR>
<ADDRESS>Apache/1.3.22 Server at 127.0.0.1 Port 8080</ADDRESS>
</BODY></HTML>
----- END
------------------------------------------------------------------------
[2002-02-08 16:26:29] torben@php.net
What happens if you try with a valid HTTP request, or just
'GET', as the custom response? The script you gave below
didn't work for me either, but did if I did either of:
$request = "GET /index.html HTTP/1.0\r\n\r\n";
...or...
$request = "GET";
Can you try that and report back?
Torben
------------------------------------------------------------------------
[2002-01-29 11:53:52] robert@gonkgonk.com
When using curl to request a page, if I just set RETURNTRANSFER
curlopt, things work as expected (output is dumped into a variable). If
I just set CUSTOMREQUEST, thinks work as expected (output is dumped to
stdout). However, if I set RETURNTRANSFER and CUSTOMREQUEST at the same
time, I get no output. The request is made, according to my apache
logs, but I get nothing. Here is some demo code:
<?
$c = curl_init();
$request = '';
$request .= 'GET /testfiles/phptest.php' . "\r\n";
curl_setopt($c, CURLOPT_URL,
'http://localhost:8080/testfiles/phptest.php');
curl_setopt($c, CURLOPT_CUSTOMREQUEST, $request);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
echo trim( curl_exec($c) );
curl_close($c);
?>
That is an example of a request that will not work. Comment either one
of the "curl_setopt" lines out and it will.
Thanks,
robert
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=15279&edit=1