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

Hello everyone,

In continuation with my post how to upload a file to a secured website? and How to authenticate and upload file to a secured server
i was able to figure out to go out of proxy to access HTTPS website by simply setting $ua->proxy(https => undef); and taking proxy from Env varaibles

Now i am able to authenitcate to a website and get the session cookie and pass it to another page for uploading a file. But i see that the file is not being uploaded atall and i always gets the return from the website as error in file importing. below is part of the code i use for upload

request=POST $upload_url,Content_Disposition => 'multipart/form-data', Content_Type=> 'application/vnd.ms-excel', Content_Type=> 'application/vnd.ms-excel', Content_Length=> 1024, submit => 1, Content => [ filename=>[$file ] ];


I am uploading a CSV file to this website.

Also, I see this error <BR

Content-Length header value was wrong, fixed at C:/Perl/lib/LWP/Protocol/http.pm line 189.


in my log Is this the reason why the file is not uploaded? also how to set correct content-length?

>
This webpage link can only be access via POST method and requires a file as parameter and returns a text file which contains the status message
>
Thanks a lot in advance
Karthik

20071111 Janitored by Corion: Linkified links, made links local, as per Writeup Formatting Tips

Replies are listed 'Best First'.
Re: File not posted to a HTTPS website
by Gangabass (Vicar) on Nov 07, 2007 at 02:37 UTC

    I'm sure you don't need to set Content_Length. HTTP::Request do all stuff for you automatically.

    Also why you specify Content_Type two times?

    And finally: why you place [] around $file?

    Try this:

    $ua->post( $upload_url, Content_Type=> 'application/vnd.ms-excel', Con +tent => $file );
      Thanks for your reply.
      The content_type was a copy paste problem. I have it only once in my code.
      Also this piece of code you had suggested did not work and i get the following error
      You need a request object, not a HTTP::Response object at Upload_V6.pl line 107
      My code always gives this erorr
      Content-Length header value was wrong, fixed at C:/Perl/lib/LWP/Protocol/http.pm line 189.

        Then get out a network sniffer or use use LWP::Debug qw(+) to see what gets sent over the wire.

        There is no way we can help you debug this situation, as you do not show us the whole code, especially line 107, nor information on the data, nor what Content-Length value you sent and why LWP::Protocol::http feels the need to override it.

        That warning might be a red herring, but you don't tell us what the server sends as result page after your upload, and you also don't tell what the server error logs say.

Re: File not posted to a HTTPS website
by moritz (Cardinal) on Nov 07, 2007 at 11:09 UTC
    BTW the Content-Length header value was wrong message seems to be just a warning, not an error message.

    You don't seem to send exactly 1024 bytes, but you explicitly set the length to 1024. So LWP::Protocol:http corrects that value, and tells you so in a warning.

      i even removed this line but still getting the same warning/error