POST data to a request stream

Terrence Brannon <[email protected]>
Newsgroups gmane.comp.lang.perl.modules.lwp
Message-ID <[email protected]>
I have modified the code I read in an earlier thread on writing data to 
a request stream:
http://www.mail-archive.com/[email protected]/msg06373.html

    my $ua = LWP::UserAgent->new();
    my $req = HTTP::Request->new(POST => $self->url);
    my $xml = $self->xml_output;
    my $length = length($xml);

    $req->content($xml);
    $req->header('Content-length' => $length);
    $req->content_type("application/octet-stream");

    my $res =  $ua->request($req);
    my $response_data = $res->content;

But the error I am getting from them is 'Root node of XML is missing' - 
which basically means to me that they did not get anything written to 
the request stream.

They provide an example of how the POST request should be done in .NET. 
So my goal is to use LWP to mimic the exact .NET commands below. The 
only difference that I can see is that I am not creating a 
"requestStream" object and then manually issuing 
requestStream.Write(postDataBytes, 0, postDataBytes.Length); but I 
assume that LWP is doing something similar under the hood.


string UploadURL = "https://www.perlrocks.com/submit.aspx?nqid=partnerid"

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(UploadURL);

string postData = null;
request.Method = "POST";
request.KeepAlive = false;
request.Timeout = 180000;

postData = XMLString;

request.ContentType = "application/octet-stream";
byte[] postDataBytes = Encoding.UTF8.GetBytes(postData);
request.ContentLength = postDataBytes.Length;

Stream requestStream = request.GetRequestStream();
requestStream.Write(postDataBytes, 0, postDataBytes.Length);
requestStream.Close();
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.