Re: PHP/pear http put method and text/xml?

From: Wolfgang May (may_at_informatik.uni-goettingen.de)
Date: 11/08/04


Date: Mon, 8 Nov 2004 17:45:15 +0000 (UTC)

Manuel Lemos <mlemos@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



Relevant Pages