HTTP::Request format.

D

Danny Woods

Hi all,

I have a script that listens on a socket, reads some XML from an
external entity, slaps a POST header on it, and POSTs it off to a Web
server for processing. So, using HTTP::Request::Common, it's a simple
matter of:

$request = POST("http://www.no-server-here.com/cgi-bin/script.cgi");
$request->header("Content-Length", length($xml));
$request->content($xml);

When sent, this looks something like:

POST http://www.no-server-here.com/cgi-bin/script.cgi
Content-Length: [some-number]

<some-xml..../>

But I have a client who (for some reason) wants:

POST /cgi-bin/script.cgi HTTP/1.0
Host: www.no-server-here.com
Content-Length: [some-number]

<some-xml..../>

?

The RFC states (at
http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html#sec5) that
requests start with a request line, which has a format of:

Method SP Request-URI SP HTTP-Version CRLF

The format for a Request-URI seems to be leaning towards the absolute
format produced by HTTP::Request, but the other format with the Host
header is still valid. In any case, the protocol and version don't
appear to be optional, and yet are missed out by HTTP::Request.

Is there any way that I'm missing to hammer the request string into
shape, or so I have to resort to sockets and hand made requests?


Many thanks,

Danny.
 
B

Ben Morrow

Danny Woods said:
$request = POST("http://www.no-server-here.com/cgi-bin/script.cgi");
$request->header("Content-Length", length($xml));
$request->content($xml);

When sent, this looks something like:

POST http://www.no-server-here.com/cgi-bin/script.cgi
Content-Length: [some-number]

<some-xml..../>

But I have a client who (for some reason) wants:

POST /cgi-bin/script.cgi HTTP/1.0
Host: www.no-server-here.com
Content-Length: [some-number]

<some-xml..../>

?

The RFC states (at
http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html#sec5) that
requests start with a request line, which has a format of:

Method SP Request-URI SP HTTP-Version CRLF

The format for a Request-URI seems to be leaning towards the absolute
format produced by HTTP::Request, but the other format with the Host
header is still valid. In any case, the protocol and version don't
appear to be optional, and yet are missed out by HTTP::Request.

This is Not Good... :)

The protocol is absolutely not optional, and can be put in with

$request->protocol("HTTP/1.0");

The Host: header is required for HTTP/1.1 and recommended for
HTTP/1.0, even if the request-URI is absolute. You can put this in
with

$request->header(host => $request->uri->host);

The server ought to accept a request in this format, i.e.

POST http://www.no-server-here.com/cgi-bin/script.cgi HTTP/1.0
Host: www.no-server-here.com
Content-Length: ...

, but if it really won't then you can make the request-URI relative
with

$request->uri($request->uri->path);

(obviously you must do this *after* you set the Host: header from the
URI :).

Note that if you use LWP::UserAgent to send the request it does all
this for you.

Ben
 
D

Danny Woods

Ben said:
Note that if you use LWP::UserAgent to send the request it does all
this for you.

Thanks, Ben.

I've been using LWP::UserAgent to actually send the request, but was
confusing things by setting up the request object and then using
$request->as_string to examine the request before sending. This shows
something rather different from what the agent actually fires out.

So the problem wasn't really a problem at all...

Thanks again,

Danny.
 
K

kz

Ben
--
$.=1;*g=sub{print@_};sub r($$\$){my($w,$x,$y)=@_;for(keys%$x){/main/&&next;*p=$
$x{$_};/(\w)::$/&&(r($w.$1,$x.$_,$y),next);$y eq\$p&&&g("$w$_")}};sub t{for(@_)
{$f&&($_||&g(" "));$f=1;r"","::",$_;$_&&&g(chr(0012))}};t # (e-mail address removed)
$J::u::s::t, $a::n::eek:::t::h::e::r, $P::e::r::l, $h::a::c::k::e::r, $.

This is OFPOS.
One Fine Piece Of Signature.
Wow!

Zoltan
 
K

kz

Ben
--
$.=1;*g=sub{print@_};sub r($$\$){my($w,$x,$y)=@_;for(keys%$x){/main/&&next;*p=$
$x{$_};/(\w)::$/&&(r($w.$1,$x.$_,$y),next);$y eq\$p&&&g("$w$_")}};sub t{for(@_)
{$f&&($_||&g(" "));$f=1;r"","::",$_;$_&&&g(chr(0012))}};t # (e-mail address removed)
$J::u::s::t, $a::n::eek:::t::h::e::r, $P::e::r::l, $h::a::c::k::e::r, $.

This is OFPOS.
One Fine Piece Of Signature.
Wow!

Zoltan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top