Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

AnyEvent::HTTP not sending ContentLength ?

by ForeverLearning (Novice)
on Mar 20, 2016 at 18:27 UTC ( [id://1158369]=perlquestion: print w/replies, xml ) Need Help??

ForeverLearning has asked for the wisdom of the Perl Monks concerning the following question:

This is how it's supposed to work, isn't it ?
my %headerArray = ( "Content-Length"=>2345 ); http_request "PUT" => $url, headers=>%headerArray, body=>$content, sub {do stuff here};

The problem I'm having is that the request goes through and the other side says "411. The request must be chunked or have a content length." The content size definitley matches the size of the body being sent.

I can't see a simple way to turn on tracing in AnyEvent::HTTP either, which isn't helping my debugging.

Replies are listed 'Best First'.
Re: AnyEvent::HTTP not sending ContentLength ?
by 1nickt (Canon) on Mar 20, 2016 at 19:29 UTC

    The docs for AnyEvent::HTTP (which I haven't used) show the headers being passed in to http_request() as a reference to a hash, not the hash itself. Try:

    my $headers = { Content-Length => 2345, }; http_request 'PUT' => $url, 'headers' => $headers, ...

    I can't see a simple way to turn on tracing in AnyEvent::HTTP either, which isn't helping my debugging.

    Maybe setting $ENV{ PERL_ANYEVENT_VERBOSE } see http://search.cpan.org/~mlehmann/AnyEvent-7.12/lib/AnyEvent.pm#ENVIRONMENT_VARIABLES


    The way forward always starts with a minimal test.
      my $headers={} did the trick. Thanks ! Also thanks to the debug pointer.
Re: AnyEvent::HTTP not sending ContentLength ?
by NetWallah (Canon) on Mar 20, 2016 at 19:27 UTC
    %headerArray gets expanded out in this list context, resulting in:

    http_request "PUT" => $url, headers=> "Content-Length"=>2345, body=>$content, sub {do stuff here};
    which is bad syntax.

    Don't have time to research the right syntax now...

            This is not an optical illusion, it just looks like one.

Re: AnyEvent::HTTP not sending ContentLength ?
by bart (Canon) on Mar 21, 2016 at 08:13 UTC
    %headerArray, as you use it, is a flat list. What you want to pass is a hash reference, thus:
    http_request "PUT" => $url, headers=>\%headerArray, body=>$content, sub {do stuff here};
    Note the backslash before the percent sign.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1158369]
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2025-06-16 18:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.