By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,467 Members | 1,308 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,467 IT Pros & Developers. It's quick & easy.

PHP/pear http put method and text/xml?

P: n/a
Hi,

I have a problem with the HTTP implementation of the PEAR package:
I try to PUT an XML instance to an XML database (eXist), but it always
puts a binary:

<?php
require_once "HTTP/Request.php";

$URL = 'http://ap34.ifi.informatik.uni-goettingen.de:8081/exist/servlet/db/may/hamlet.xml';

$req =& new HTTP_Request("");
$req->setBasicAuth($user, $passwd);
$req->setURL($URL);
$req->setMethod("PUT");
$req->addHeader("Content-Type", "text/xml");
$req->addFile("hamlet.xml","/home/may/public_html/PHP/hamlet.xml", "text/xml");

$response = $req->sendRequest();
?>

When looking into the database, there is also not the XML file, but
there is a complete HTTP request:

***
--HTTP_Request_f42cc34621bc820ecd46b8f6ef61eb7e
Content-Disposition: form-data; name="hamlet.xml"; filename="hamlet.xml"
Content-Type: text/xml

<?xml version="1.0"?>
<!DOCTYPE PLAY SYSTEM "play.dtd">

<PLAY>
<TITLE>The Tragedy of Hamlet, Prince of Denmark</TITLE>
etc.
****

It seems not ot be a problem of the database, since it works well when doing
the same with python (a sample that is included into the documentation of eXist),
i.e., tha database work correctly when it receives a correct PUT.
Can anybody give me an example how HTTP PUT is applied correctly with PEAR?

THX,
Wolfgang
Jul 17 '05 #1
Share this Question
Share on Google+
13 Replies


P: n/a
Hello,

On 10/25/2004 02:29 PM, Wolfgang May wrote:
It seems not ot be a problem of the database, since it works well when doing
the same with python (a sample that is included into the documentation of eXist),
i.e., tha database work correctly when it receives a correct PUT.
Can anybody give me an example how HTTP PUT is applied correctly with PEAR?


That is the way to send files with POST. PUT is different.

I do not use PEAR classes, so I can't tell you if it can do what you
want. I use this other HTTP client class that lets you send HTTP
requests with arbitrary bodies:

http://www.phpclasses.org/httpclient

--

Regards,
Manuel Lemos

PHP Classes - Free ready to use OOP components written in PHP
http://www.phpclasses.org/

PHP Reviews - Reviews of PHP books and other products
http://www.phpclasses.org/reviews/

Metastorage - Data object relational mapping layer generator
http://www.meta-language.net/metastorage.html
Jul 17 '05 #2

P: n/a
Manuel Lemos <ml****@acm.org> wrote:
Hello,

On 10/25/2004 02:29 PM, Wolfgang May wrote:
It seems not ot be a problem of the database, since it works well when doing
the same with python (a sample that is included into the documentation of eXist),
i.e., tha database work correctly when it receives a correct PUT.
Can anybody give me an example how HTTP PUT is applied correctly with PEAR?
That is the way to send files with POST. PUT is different.


I think so ...
I do not use PEAR classes, so I can't tell you if it can do what you
want. I use this other HTTP client class that lets you send HTTP
requests with arbitrary bodies:

http://www.phpclasses.org/httpclient


The site seems to be inaccessible, and as far as I understand from
http://scripts.incutio.com/httpclient/index.php (which also contains a description
of this class), this supports only get/post.

Wolfgang
Jul 17 '05 #3

P: n/a
Hello,

On 10/25/2004 04:47 PM, Wolfgang May wrote:
It seems not ot be a problem of the database, since it works well when doing
the same with python (a sample that is included into the documentation of eXist),
i.e., tha database work correctly when it receives a correct PUT.
Can anybody give me an example how HTTP PUT is applied correctly with PEAR?
That is the way to send files with POST. PUT is different.

I think so ...


PUT is much simpler because you just add the file to the request body.

I do not use PEAR classes, so I can't tell you if it can do what you
want. I use this other HTTP client class that lets you send HTTP
requests with arbitrary bodies:

http://www.phpclasses.org/httpclient

The site seems to be inaccessible, and as far as I understand from


It was just a temporary stop. It is accessible now.

http://scripts.incutio.com/httpclient/index.php (which also contains a description
of this class), this supports only get/post.


No, you just set the RequestMethod argument to PUT and pass file data to
the the Body request argument. Take a look at the test_http_soap.php
example for a demonstration.

--

Regards,
Manuel Lemos

PHP Classes - Free ready to use OOP components written in PHP
http://www.phpclasses.org/

PHP Reviews - Reviews of PHP books and other products
http://www.phpclasses.org/reviews/

Metastorage - Data object relational mapping layer generator
http://www.meta-language.net/metastorage.html
Jul 17 '05 #4

P: n/a
Manuel Lemos <ml****@acm.org> wrote:
Hello,

On 10/25/2004 04:47 PM, Wolfgang May wrote:
It seems not ot be a problem of the database, since it works well when doing
the same with python (a sample that is included into the documentation of eXist),
i.e., tha database work correctly when it receives a correct PUT.
Can anybody give me an example how HTTP PUT is applied correctly with PEAR?

That is the way to send files with POST. PUT is different.

I think so ...


PUT is much simpler because you just add the file to the request body.


.... but not easy enough for me.
(anyway, I also did not find out how to do authorization with this package).
Sometimes a documentation would be useful (and this was one of the reasons why I tried
first to use the PEAR classes).
http://scripts.incutio.com/httpclient/index.php (which also contains a description
of this class), this supports only get/post.


.... it seems to be another PHP class, also called httpclient.
No, you just set the RequestMethod argument to PUT and pass file data to
the the Body request argument. Take a look at the test_http_soap.php
example for a demonstration.


I wanted to use these things in a course, but the results up to now
showed me that PHP seems not to be the right thing for this. Too many
similar, but different classes for the same things, with too less
documentation.

Wolfgang
Jul 17 '05 #5

P: n/a
Hello,

On 10/28/2004 06:57 AM, Wolfgang May wrote:
>It seems not ot be a problem of the database, since it works well when doing
>the same with python (a sample that is included into the documentation of eXist),
>i.e., tha database work correctly when it receives a correct PUT.
>Can anybody give me an example how HTTP PUT is applied correctly with PEAR?

That is the way to send files with POST. PUT is different.
I think so ...
PUT is much simpler because you just add the file to the request body.

... but not easy enough for me.
(anyway, I also did not find out how to do authorization with this package).


You just have to specify the URL like you do with a browser:

http://user:pa******@www.domain.com/uri/etc/

Sometimes a documentation would be useful (and this was one of the reasons why I tried
first to use the PEAR classes).


Right, but sometimes developers do not find enough time to produce
proper documentation. Many PEAR packages do not have proper documentation.

At least with this class you have many examples with comments in English
from which you can learn.

No, you just set the RequestMethod argument to PUT and pass file data to
the the Body request argument. Take a look at the test_http_soap.php
example for a demonstration.

I wanted to use these things in a course, but the results up to now
showed me that PHP seems not to be the right thing for this. Too many
similar, but different classes for the same things, with too less
documentation.


I don't think that as to do with PHP but rather with the fact that it
takes a lot of time to produce documentation. Since this is free
software it is hard to justify the time that it takes. Some developers
try to do it sooner rather than later, but that is not a specific
problem of PHP.

--

Regards,
Manuel Lemos

PHP Classes - Free ready to use OOP components written in PHP
http://www.phpclasses.org/

PHP Reviews - Reviews of PHP books and other products
http://www.phpclasses.org/reviews/

Metastorage - Data object relational mapping layer generator
http://www.meta-language.net/metastorage.html
Jul 17 '05 #6

P: n/a
Manuel Lemos <ml****@acm.org> wrote:
(anyway, I also did not find out how to do authorization with this package).


You just have to specify the URL like you do with a browser:

http://user:pa******@www.domain.com/uri/etc/


This is not understood by the server (same for GET, but for the PEAR classes,
setBasicAuth works fine). Although, I then experimented without access restrictions ...
No, you just set the RequestMethod argument to PUT and pass file data to
the the Body request argument. Take a look at the test_http_soap.php
example for a demonstration.


require("http.php");

set_time_limit(0);
$http=new http_class;
$url="...";
$http->GetRequestArguments($url,$arguments);
$arguments["RequestMethod"]="PUT";
$arguments["Headers"]["Content-Type"]="text/xml; charset=\"utf-8\"";
$arguments["Body"]="<?xml version='1.0' encoding='UTF-8'?><name>bla</name>";
+ and the remaining part of the soap test
.... and it answers:

***
Response body:

HTTP/1.1 200 OK
Date: Mon, 01 Nov 2004 16:53:28 GMT
Server: Jetty/4.1.4 (Linux 2.4.20-gk20030509 i386)
Servlet-Engine: Jetty/4.1.4 (Servlet 2.3; JSP 1.2; java 1.4.2)
Content-Type: text/xml; charset=UTF-8
Transfer-Encoding: chunked

2b
Document bla.xml stored as binary resource.
0
***

and puts the document as a *binary*.

It's not a problem of the server, since HTTP PUT with python works.
Can you tell me what I am still doing wrong?

Wolfgang

Jul 17 '05 #7

P: n/a
Hello,

On 11/01/2004 02:58 PM, Wolfgang May wrote:
(anyway, I also did not find out how to do authorization with this package).


You just have to specify the URL like you do with a browser:

http://user:pa******@www.domain.com/uri/etc/

This is not understood by the server (same for GET, but for the PEAR classes,
setBasicAuth works fine). Although, I then experimented without access restrictions ...


I was not talking about PEAR classes. As I said I do not use them.

You can use such type of URL with the HTTP client class that I mentioned.

No, you just set the RequestMethod argument to PUT and pass file data to
the the Body request argument. Take a look at the test_http_soap.php
example for a demonstration.

require("http.php");

set_time_limit(0);
$http=new http_class;
$url="...";
$http->GetRequestArguments($url,$arguments);
$arguments["RequestMethod"]="PUT";
$arguments["Headers"]["Content-Type"]="text/xml; charset=\"utf-8\"";
$arguments["Body"]="<?xml version='1.0' encoding='UTF-8'?><name>bla</name>";
+ and the remaining part of the soap test
... and it answers:

***
Response body:

HTTP/1.1 200 OK
Date: Mon, 01 Nov 2004 16:53:28 GMT
Server: Jetty/4.1.4 (Linux 2.4.20-gk20030509 i386)
Servlet-Engine: Jetty/4.1.4 (Servlet 2.3; JSP 1.2; java 1.4.2)
Content-Type: text/xml; charset=UTF-8
Transfer-Encoding: chunked

2b
Document bla.xml stored as binary resource.
0
***

and puts the document as a *binary*.

It's not a problem of the server, since HTTP PUT with python works.
Can you tell me what I am still doing wrong?


Nothing. Isn't that the expected response?
--

Regards,
Manuel Lemos

PHP Classes - Free ready to use OOP components written in PHP
http://www.phpclasses.org/

PHP Reviews - Reviews of PHP books and other products
http://www.phpclasses.org/reviews/

Metastorage - Data object relational mapping layer generator
http://www.meta-language.net/metastorage.html
Jul 17 '05 #8

P: n/a
Manuel Lemos <ml****@acm.org> wrote:
Hello,

On 11/01/2004 02:58 PM, Wolfgang May wrote:
(anyway, I also did not find out how to do authorization with this package).

You just have to specify the URL like you do with a browser:

http://user:pa******@www.domain.com/uri/etc/

This is not understood by the server (same for GET, but for the PEAR classes,
setBasicAuth works fine). Although, I then experimented without access restrictions ...


I was not talking about PEAR classes. As I said I do not use them.

You can use such type of URL with the HTTP client class that I mentioned.


No, as I said, the server does not understand them.
But, it understands authenthification via the setBasicAuth() method as provided by
e.g. the PEAR classes. The package you mentioned does -at least as far as I can see
from the documentation- not support this.
$url="...";
$http->GetRequestArguments($url,$arguments);
$arguments["RequestMethod"]="PUT";
$arguments["Headers"]["Content-Type"]="text/xml; charset=\"utf-8\"";
$arguments["Body"]="<?xml version='1.0' encoding='UTF-8'?><name>bla</name>";
+ and the remaining part of the soap test
... and it answers:

***
Response body:

HTTP/1.1 200 OK
Date: Mon, 01 Nov 2004 16:53:28 GMT
Server: Jetty/4.1.4 (Linux 2.4.20-gk20030509 i386)
Servlet-Engine: Jetty/4.1.4 (Servlet 2.3; JSP 1.2; java 1.4.2)
Content-Type: text/xml; charset=UTF-8
Transfer-Encoding: chunked

2b
Document bla.xml stored as binary resource.
0
***

and puts the document as a *binary*.

It's not a problem of the server, since HTTP PUT with python works.
Can you tell me what I am still doing wrong?


Nothing. Isn't that the expected response?


No, with specifying "ContentType='text/xml'" I would expect that it
puts it as XML, not as a binary. When putting it as a binary, the XML
database system does not recognize it. The same thing works
well, when doing HTTP PUT by python or Java, so the problem is not due
to the receiving system.

Wolfgang
Jul 17 '05 #9

P: n/a
Hello,

On 11/04/2004 06:45 AM, Wolfgang May wrote:
>(anyway, I also did not find out how to do authorization with this package).

You just have to specify the URL like you do with a browser:

http://user:pa******@www.domain.com/uri/etc/
This is not understood by the server (same for GET, but for the PEAR classes,
setBasicAuth works fine). Although, I then experimented without access restrictions ...


I was not talking about PEAR classes. As I said I do not use them.

You can use such type of URL with the HTTP client class that I mentioned.

No, as I said, the server does not understand them.
But, it understands authenthification via the setBasicAuth() method as provided by
e.g. the PEAR classes. The package you mentioned does -at least as far as I can see
from the documentation- not support this.


I think you are confused. The class from
http://www.phpclasses.org/httpclient does support that when you call
GetRequestArguments function and it does not come with documentation.
Are you sure you are seeing the same class?

$url="...";
$http->GetRequestArguments($url,$arguments);
$arguments["RequestMethod"]="PUT";
$arguments["Headers"]["Content-Type"]="text/xml; charset=\"utf-8\"";
$arguments["Body"]="<?xml version='1.0' encoding='UTF-8'?><name>bla</name>";
+ and the remaining part of the soap test
... and it answers:

***
Response body:

HTTP/1.1 200 OK
Date: Mon, 01 Nov 2004 16:53:28 GMT
Server: Jetty/4.1.4 (Linux 2.4.20-gk20030509 i386)
Servlet-Engine: Jetty/4.1.4 (Servlet 2.3; JSP 1.2; java 1.4.2)
Content-Type: text/xml; charset=UTF-8
Transfer-Encoding: chunked

2b
Document bla.xml stored as binary resource.
0
***

and puts the document as a *binary*.

It's not a problem of the server, since HTTP PUT with python works.
Can you tell me what I am still doing wrong?


Nothing. Isn't that the expected response?

No, with specifying "ContentType='text/xml'" I would expect that it
puts it as XML, not as a binary. When putting it as a binary, the XML
database system does not recognize it. The same thing works
well, when doing HTTP PUT by python or Java, so the problem is not due
to the receiving system.


And what message appears when you do HTTP PUT with Python or Java?

Another thing that is odd is the httpclient class handles chunked
transfer encoding correctly, so you should not see those hexadecimal
charcters (2b 0) in the response. Are you sure that is the same
response that is returned when you use the httpclient class or that is
the response when using the PEAR class?
--

Regards,
Manuel Lemos

PHP Classes - Free ready to use OOP components written in PHP
http://www.phpclasses.org/

PHP Reviews - Reviews of PHP books and other products
http://www.phpclasses.org/reviews/

Metastorage - Data object relational mapping layer generator
http://www.meta-language.net/metastorage.html
Jul 17 '05 #10

P: n/a
Wolfgang May wrote:

[Unattributed source wrote:]
> http://user:pa******@www.domain.com/uri/etc/

That's not an HTTP URI.
No, as I said, the server does not understand them.


It's no less of a server for not honouring them.

Roll on the weekend!

--
Jock
Jul 17 '05 #11

P: n/a
Manuel Lemos <ml****@acm.org> wrote:
No, as I said, the server does not understand them.
But, it understands authenthification via the setBasicAuth() method as provided by
e.g. the PEAR classes. The package you mentioned does -at least as far as I can see
from the documentation- not support this.
I think you are confused. The class from
http://www.phpclasses.org/httpclient does support that when you call
GetRequestArguments function and it does not come with documentation.
Are you sure you are seeing the same class?


Yes. As you insisted in a previous posting that the examples serve as documentation,
I tacitly adopted this terminology.
***
Response body:

HTTP/1.1 200 OK
Date: Mon, 01 Nov 2004 16:53:28 GMT
Server: Jetty/4.1.4 (Linux 2.4.20-gk20030509 i386)
Servlet-Engine: Jetty/4.1.4 (Servlet 2.3; JSP 1.2; java 1.4.2)
Content-Type: text/xml; charset=UTF-8
Transfer-Encoding: chunked

2b
Document bla.xml stored as binary resource.
0
***

and puts the document as a *binary*.

It's not a problem of the server, since HTTP PUT with python works.
Can you tell me what I am still doing wrong?

Nothing. Isn't that the expected response?

No, with specifying "ContentType='text/xml'" I would expect that it
puts it as XML, not as a binary. When putting it as a binary, the XML
database system does not recognize it. The same thing works
well, when doing HTTP PUT by python or Java, so the problem is not due
to the receiving system.


And what message appears when you do HTTP PUT with Python or Java?


reading file hamlet.xml ...
hamlet.xml
storing document to collection /db/may ...
Ok.

and then it is accessible in the database.
Another thing that is odd is the httpclient class handles chunked
transfer encoding correctly, so you should not see those hexadecimal
charcters (2b 0) in the response. Are you sure that is the same
response that is returned when you use the httpclient class or that is
the response when using the PEAR class?


It was the response when I used the httpclient class (created by the output
routines from your test_http_soap example).

In the meantime, a small part of the problem is solved:
we found out that the server ignores the content type
declaration when it is not exactly "text/xml" (but extended with parameters).

But, after fixing this, I am still back with the original question: how
to do PUT with HTTP with any PHP class. Writing the XML in the body (as in your
SOAP example) as

$http=new http_class;
$url="http://ap34.ifi.informatik.uni-goettingen.de:8081/exist/servlet/db/may/bla.xml";
$http->GetRequestArguments($url,$arguments);
$arguments["RequestMethod"]="PUT";
$arguments["Headers"]["Content-Type"]="text/xml";
$arguments["Body"]="<?xml version='1.0' encoding='UTF-8'?><name>bla</name>";

does not work:

http/1.1 400 parsing+exception%3a+premature+end+of+file%2e:

Even if I add an explicit attribute for the content length,
$arguments["Headers"]["Content-length"]=54;
(or instead of 54 any number like 3 or 1000), it waits for some time and returns

http/1.1 500 read+timed+out:

Wolfgang
Jul 17 '05 #12

P: n/a
Hello,

On 11/08/2004 03:45 PM, Wolfgang May wrote:
No, as I said, the server does not understand them.
But, it understands authenthification via the setBasicAuth() method as provided by
e.g. the PEAR classes. The package you mentioned does -at least as far as I can see
from the documentation- not support this.
I think you are confused. The class from
http://www.phpclasses.org/httpclient does support that when you call
GetRequestArguments function and it does not come with documentation.
Are you sure you are seeing the same class?

Yes. As you insisted in a previous posting that the examples serve as documentation,
I tacitly adopted this terminology.


I did not say that examples serve as documentation, but you can learn
from the examples because they are commented step by step like in a
tutorial.

In this case, the main example comes with an explanation on how to set
the user and password for authentication by setting the URL passed to
the GetRequestArguments function. I suppose you were not looking at the
main example.
But, after fixing this, I am still back with the original question: how
to do PUT with HTTP with any PHP class. Writing the XML in the body (as in your
SOAP example) as

$http=new http_class;
$url="http://ap34.ifi.informatik.uni-goettingen.de:8081/exist/servlet/db/may/bla.xml";
$http->GetRequestArguments($url,$arguments);
$arguments["RequestMethod"]="PUT";
$arguments["Headers"]["Content-Type"]="text/xml";
$arguments["Body"]="<?xml version='1.0' encoding='UTF-8'?><name>bla</name>";

does not work:

http/1.1 400 parsing+exception%3a+premature+end+of+file%2e:

Even if I add an explicit attribute for the content length,
$arguments["Headers"]["Content-length"]=54;
(or instead of 54 any number like 3 or 1000), it waits for some time and returns

http/1.1 500 read+timed+out:


The content-length header is not necessary but if you put the server
will wait exactly for that amount of data.

Anyway, there was indeed a bug in the class that was sending custom
request body data for HTTP POST methods. That is why the server was
waiting for the data until it timed out.

I have just fixed it and it worked with the URLs you supplied. You may
download the updated version now from the site. Thank you for reporting
the problem.

http://www.phpclasses.org/httpclient
--

Regards,
Manuel Lemos

PHP Classes - Free ready to use OOP components written in PHP
http://www.phpclasses.org/

PHP Reviews - Reviews of PHP books and other products
http://www.phpclasses.org/reviews/

Metastorage - Data object relational mapping layer generator
http://www.meta-language.net/metastorage.html
Jul 17 '05 #13

P: n/a
Manuel Lemos <ml****@acm.org> wrote:
But, after fixing this, I am still back with the original question: how
to do PUT with HTTP with any PHP class. Writing the XML in the body (as in your
SOAP example) as

$http=new http_class;
$url="http://ap34.ifi.informatik.uni-goettingen.de:8081/exist/servlet/db/may/bla.xml";
$http->GetRequestArguments($url,$arguments);
$arguments["RequestMethod"]="PUT";
$arguments["Headers"]["Content-Type"]="text/xml";
$arguments["Body"]="<?xml version='1.0' encoding='UTF-8'?><name>bla</name>";

does not work:

http/1.1 400 parsing+exception%3a+premature+end+of+file%2e:

Even if I add an explicit attribute for the content length,
$arguments["Headers"]["Content-length"]=54;
(or instead of 54 any number like 3 or 1000), it waits for some time and returns

http/1.1 500 read+timed+out:


The content-length header is not necessary but if you put the server
will wait exactly for that amount of data.

Anyway, there was indeed a bug in the class that was sending custom
request body data for HTTP POST methods. That is why the server was
waiting for the data until it timed out.

I have just fixed it and it worked with the URLs you supplied. You may
download the updated version now from the site. Thank you for reporting
the problem.

http://www.phpclasses.org/httpclient


THX.
It works now.

Wolfgang
Jul 17 '05 #14

This discussion thread is closed

Replies have been disabled for this discussion.