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

I have to set the User-Agent in the header but I can't figure out how to do it. My code, which is something like this:
my $client = SOAP::Lite -> uri($uri) -> proxy($proxy) -> call($method);
produces this:
SOAP::Transport::HTTP::Client::send_receive: POST http://... Accept: text/xml Accept: multipart/* Content-Length: 622 Content-Type: text/xml; charset=utf-8 SOAPAction: "http://..."
As you can see there's no User-Agent. Am I missing something or is there a way to fix this?

Replies are listed 'Best First'.
Re: setting User-Agent, using SOAP::Lite
by Anonymous Monk on Feb 07, 2002 at 01:47 UTC
    SOAP::Lite is a web (rimshot) of OO Classes. With the help of the perl debugger, you can begin to see what's going on. As it turns out, SOAP::Lite has a member called SOAP::Lite::Transport::HTTP::Client which is a subclass of LWP::UserAgent. What's more, you can *get* to the UserAgent object after you have defined the proxy thusly:
    my $client = SOAP::Lite->uri("http://foo.com"); $client->proxy("http://foo.com/soap_server"); $client->transport->agent("Go_Pound_Sand/1.1");

      I noticed I wasn't logged in *after* I posted. Sigh. Anyway, that code should do the trick. As always, the perl debugger is great tool for getting to the bottom of Class hierarchies. For fun, try stepping through Tk. I learned some truly vile tricks from that beastie. :-)

      Cheers.

      --jjohn

Re: setting User-Agent, using SOAP::Lite
by webengr (Pilgrim) on Feb 07, 2002 at 01:42 UTC

    I cannot answer your question directly, but I can offer a possible clue: I noticed in the documentation for SOAP::Transport::HTTP::Client that it has in its dependencies list LWP::UserAgent, which does have a method for setting the value of Useragent.

    So here's my (untested) guess:

    $client->agent($ua_string);

    Hope this gets you moving in the right direction.



    PCS