471,616 Members | 1,751 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,616 software developers and data experts.

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
Aug 11 '05 #1
1 2031
"John Smith" <jo*******@theweather.com.au> wrote:

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;
?>


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, ti**@probo.com
Providenza & Boekelheide, Inc.
Aug 11 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Yannick Turgeon | last post: by
10 posts views Thread by Lisa Pearlson | last post: by
reply views Thread by CFloyd | last post: by
1 post views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.