Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

"Bad" http headers in LWP::UserAgent

by adamm (Initiate)
on Sep 19, 2012 at 10:22 UTC ( #994445=perlquestion: print w/ replies, xml ) Need Help??
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

Comment on "Bad" http headers in LWP::UserAgent
Select or Download Code
Re: "Bad" http headers in LWP::UserAgent
by MidLifeXis (Prior) 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 (Abbot) 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'

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (7)
As of 2014-10-25 12:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (143 votes), past polls