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

I'm using the YouTube API and they require a user to send an HTTP post with the 'data' of a video (title, description, etc) in XML format. I find the size of my xml using
length($xmldata);
and it returns me the correct number of bytes.
However, when I set up my headers for my post and include this content-length, it seems as if the content-length value is too high because I get the following when I run the script from the command line:
% Total % Received % Xferd Average Speed Time Time Time + Current Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- 0:00:42 --:--: +-- 0

...it's as if it is waiting for more data from me.
I tinkered with the content-length and found a good value where the post was accepted and went through perfectly, but I need my program to figure out this value.

Any suggestions on how content-length works in http headers and how I can get the correct value to send? I also tried opening/writing/closing a file and then doing a filesize on the file, but it's the same value as the perl 'length' function.

Thank you

Replies are listed 'Best First'.
Re: Determining content-length for an HTTP Post
by WizardOfUz (Friar) on Nov 25, 2009 at 17:46 UTC

    Just to rule out an encoding issue: Have you tried using the bytes pragma?

      How would I go about using it?
        use bytes; my $length_in_bytes = length( $xmldata );
Re: Determining content-length for an HTTP Post
by Anonymous Monk on Nov 25, 2009 at 17:47 UTC
    I think I just discovered the problem.

    I am sending the post as

    Content-Type:application/atom+xml; charset=UTF-8
    It's possible that the number of bytes once it's been converted to this content-type is different than the ascii value.

    How would I go about determining the length/size of my data if the type is "Content-Type:application/atom+xml; charset=UTF-8" ?
      See above :-)
        Thank you, I looked it up and tried it, but it's returning the same numerical value as it did before I added 'use bytes;' to my program.
        Where do I go from here?