I need to send requests that are formatted exactly as I specify, including whitespace. What’s the best way to achieve this?
Example of the kind of request I want to send:
GET
/
key=val
Host:example.com
The protocol is a simple request-response protocol like HTTP. I’d prefer to take advantage of LWP’s existing code where possible.
I think it is be achievable with LWP. It’s a bit of work, to be honest.
I’ve take a look at it, and you need to actually implement your own protocol (see
LWP::Protocol) because that’s where the actual request is created. Afterwards, you will need to enable that protocol as implementor of http (or https):For an example, take a look at
LWP::Protocol::GHTTPcode.Simply saying, you need to create a package implementing a
requestmethod. In that method, you need to assemble the request, open the connection, send it and receive the response.Here’s a simple working example.
MyFunkyProto.pm:
script.pl:
Note that you will actually want to construct the request (and obtain the host and port) from the
$requestobject. Or if you’re lazy, just store it somewhere in that object.