xmlrpc: no content-length in response

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • emielvl@yahoo.co.uk

    xmlrpc: no content-length in response

    Hello,

    I'm developing a client/server architecture based on the XML-RPC
    implementation in php4. All works pretty well, except that in the
    response from the server there is no "Content-Length" in the header.
    Since the XML-RPC specification requires this header to be present in
    the server response, some libraries (notably: libxmlrpc++) choke on
    this. For clarity, here's a (simple) server (slightly altered from:
    Founded in 1997, DEVShed is the perfect place for web developers to learn, share their work, and build upon the ideas of others.


    --- xmlrpc-server.php ---
    <?php

    function checkVersion_fu nc( $method_name, $params, $app_data ) {
    return 0.12;
    }

    xmlrpc_server_r egister_method( $xmlrpc_server, "checkVersi on",
    "checkVersion_f unc");

    /*
    * When an XML-RPC request is sent to this script, it
    * can be found in the raw post data.
    */
    $HTTP_RAW_POST_ DATA = isset($HTTP_RAW _POST_DATA) ? $HTTP_RAW_POST_ DATA
    : "";

    $request_xml = $HTTP_RAW_POST_ DATA;


    /*
    * The xmlrpc_server_c all_method() sends a request to
    * the server and returns the response XML. In this case,
    * it sends the raw post data we got before. It requires
    * 3 arguments:
    * The first is the handle of a server created with
    * xmlrpc_server_c reate(), the second is a string containing
    * an XML-RPC request, and the third is for application data.
    * Whatever is passed into the third parameter of this function
    * is passed as the third paramater of the PHP function that the
    * request is asking for.
    */
    $response = xmlrpc_server_c all_method($xml rpc_server, $request_xml,
    '');

    // Now we print the response for the client to read.
    print $response;

    xmlrpc_server_d estroy($xmlrpc_ server);

    ?>
    --- end ---

    Now, if we call 'checkVersion' with an RPC client, the output from
    ngrep is this:

    --- ngrep ---
    ####
    T xxxxx:52266 -> xxxxx:80 [AP]
    POST /~xxxxx/pb/xmlrpc-server.php HTTP/1.1.
    User-Agent: XMLRPCCocoa.
    Host: xxxxxx
    Pragma: no-cache.
    Accept: */*.
    Content-Type: text/xml.
    Content-Length: 110.
    ..
    <?xml version="1.0"?>
    <methodCall>
    ..<methodName>c heckVersion</methodName>
    ..<params>
    ...</params>
    ..</methodCall>
    ##
    T xxxxx:80 -> xxxxx:52266 [AP]
    HTTP/1.1 200 OK.
    Date: Tue, 14 Feb 2006 17:20:21 GMT.
    Server: Apache/1.3.34 (Ubuntu) PHP/4.4.2-1.
    X-Powered-By: PHP/4.4.2-1.
    Transfer-Encoding: chunked.
    Content-Type: text/html; charset=iso-8859-1.
    ..
    a7 .
    <?xml version="1.0" encoding="iso-8859-1"?>
    <methodResponse >
    <params>
    <param>
    <value>
    <double>0.12000 0</double>
    </value>
    </param>
    </params>
    </methodResponse>

    --- end ---

    As you can see, there is no "Content-Length" in the response. Am I
    doing something wrong here, or could this be a bug in php? Btw. I tried
    this on different servers, with the same results.

    Server version info:
    Platform: Linux (ubuntu)
    Apache: 1.3.34
    PHP: 4.4.2-1
    XMLRPC: xmlrpc-epi v. 0.51

    Thanks for any help,
    Emiel.

  • Jasen Betts

    #2
    Re: xmlrpc: no content-length in response

    On 2006-02-14, emielvl@yahoo.c o.uk <emielvl@yahoo. co.uk> wrote:[color=blue]
    > Hello,
    >
    > I'm developing a client/server architecture based on the XML-RPC
    > implementation in php4. All works pretty well, except that in the
    > response from the server there is no "Content-Length" in the header.
    > Since the XML-RPC specification requires this header to be present in
    > the server response, some libraries (notably: libxmlrpc++) choke on
    > this. For clarity, here's a (simple) server (slightly altered from:
    > http://www.devshed.com/c/a/PHP/Using...-with-PHP/4/):[/color]

    use output buffering ob_start(). measure the length of the output,
    make the header, emit the buffered output.
    [color=blue]
    > HTTP/1.1 200 OK.
    > Date: Tue, 14 Feb 2006 17:20:21 GMT.
    > Server: Apache/1.3.34 (Ubuntu) PHP/4.4.2-1.
    > X-Powered-By: PHP/4.4.2-1.
    > Transfer-Encoding: chunked.
    > Content-Type: text/html; charset=iso-8859-1.
    > .
    > a7 .[/color]
    [color=blue]
    > As you can see, there is no "Content-Length" in the response. Am I
    > doing something wrong here,[/color]

    No. it's using chunks instead.
    [color=blue]
    > or could this be a bug in php? Btw. I tried
    > this on different servers, with the same results.[/color]

    "Transfer-Encoding: chunked." is a valid alternative to "Content-Length:..."
    if XMLRPC doesn't support it it's lying where it claims HTTP/1.1

    Bye.
    Jasen

    Comment

    Working...