Headers - returning specified HTTP headers from a POST

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John Smith

    #1

    Headers - returning specified HTTP headers from a POST

    I'm writing a service which accepts a POST call, updates a database and
    returns raw HTTP headers as specified below:

    HTTP/1.1 200 OK
    Content-type:text/plain
    Content-length:3

    OK

    The code runs, and returns my headers, but only after its own:

    HTTP/1.1 100 Continue
    Server: Microsoft-IIS/5.1
    Date: Wed, 10 Aug 2005 21:45:58 GMT

    HTTP/1.1 200 OK
    Server: Microsoft-IIS/5.1
    Date: Wed, 10 Aug 2005 21:45:58 GMT
    Connection: close
    Content-type:text/plain
    Content-length:3

    OK

    Here's some static code which replicates the problem:

    <?php
    header( "HTTP/1.1 200 OK\r\n" );
    header( "Content-type:text/plain\r\n" );
    header( "Content-length:3\r\n" );
    header( "\r\n" );
    header( "OK \n" );
    exit;
    ?>

    The platform is IIS 5.1 (obviously) and we're using PHP 4.3.10.

    If it can't be solved in PHP but can in Perl, ASP or some other language,
    please let me know. Likewise if it can be solved on Apache/Linux/PHP 5. I
    really didn't expect this to be a problem.

    Thanks in advance. Did I mention that this is urgent?

    Iain


  • Tim Roberts

    #2
    Re: Headers - returning specified HTTP headers from a POST

    "John Smith" <johnsmith@thew eather.com.au> wrote:[color=blue]
    >
    >Here's some static code which replicates the problem:
    >
    ><?php
    >header( "HTTP/1.1 200 OK\r\n" );
    >header( "Content-type:text/plain\r\n" );
    >header( "Content-length:3\r\n" );
    >header( "\r\n" );
    >header( "OK \n" );
    >exit;
    >?>[/color]

    Couple of problems. First, Apache will add the HTTP header, not you.
    Next, each call to header() gets its own newline -- you don't provide it.
    Next, "OK" is not a header, it is the body. This will do what you want:

    ===== cut here =====
    <?php
    header( "Content-type:text/plain" );
    ?>
    OK
    ===== cut here =====
    --
    - Tim Roberts, timr@probo.com
    Providenza & Boekelheide, Inc.

    Comment

    Working...