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

Hello, I am building my first perl App and got problem i cannot resolve. My app sends an http request to the server using LWP::UserAgent module I set my headers in my code, but sniffer shows something different.
The code:

my $ua = LWP::UserAgent->new(); my $req= HTTP::Request->new('POST', $url); $req->content_type('text/xml, charset=utf-8'); $req->content($postdata); $req->header('SOAPAction' => '"loginRequest"'); $req->header('Connection' => 'keep-alive'); $req->header('User-Agent' => $App.' '.$Version); $req->header('Accept text/xml' => 'multipart/related'); my $response = $ua->prepare_request($req); print $req->as_string; $response = $ua->send_request($req);

The print instruction near the bottom shows correct headers, but wireshark exposes something different.
print output:

POST http://192.168.2.46:7191/soap Connection: keep-alive User-Agent: ProxyApp 1.00 Content-Type: text/xml, charset=utf-8 Accept Text/Xml: multipart/related SOAPAction: "loginRequest"

Wireshark output:

POST /soap HTTP/1.1 TE: deflate,gzip;q=0.3 Connection: keep-alive, TE, close Host: 192.168.2.46:7191 User-Agent: ProxyApp 1.00 Content-Type: text/xml, charset=utf-8 Accept Text/Xml: multipart/related SOAPAction: "loginRequest" Content-Length: 369

I would like to get rid of the 'TE' header, have 'Connection' value "keep-alive" only.
I am not shure if that 'Accept Text/Xml' should be 'Accept text/xml'
I am using perl v5.12.3

Thanks in advance

Replies are listed 'Best First'.
Re: "Bad" http headers in LWP::UserAgent
by MidLifeXis (Monsignor) on Sep 19, 2012 at 12:58 UTC

    Should Accept Text/Xml: multipart/related be Accept: ...? See RFC 2616. IIRC, header names are not supposed to have spaces in them (check my memory, please).

    What reason are you looking to disable some of the features that LWP is able to support under the hood? Is the server unable to handle those? Or are these changes trying to 'fix' some other symptom that you are seeing.

    If you do need to remove these headers, fine, but with my question on the Accept header, I am wondering if this might be a bug hunt with the wrong target.

    --MidLifeXis

Re: "Bad" http headers in LWP::UserAgent
by tobyink (Canon) on Sep 19, 2012 at 13:24 UTC
    $req->header('Accept text/xml' => 'multipart/related');

    Wuh?!

    I think you meant:

    $req->header(Accept => 'text/xml, multipart/related');
    perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'