First off, regarding Perl and coding in general I have just started to learn so it would be great if you could give me easy to understand/execute answers. Now onto the real problem:

I'm trying to create a tool for a JIRA server at my workplace. But I can't seem to get a response from the server. I already struggle with the login, which takes a JSON string as a POST request and sends back a JSON string with cookie information. I've tried through the browser and with JavaScript, that somehow works, but Perl gives me a 500 status code response. I've already tried JIRA::REST


use JIRA::REST; use JSON; my $jira = JIRA::REST->new('https://jira.hostname:PORT/jira', 'myuser' +, 'mypass'); my $request = $jira->POST("/issue/search", undef, { jql=> 'project ~ MYPROJECT and status = closed', starAt=> 0, maxResults=>1, fields=>[asignee], }); print(parse_json ($request));

Then I tried REST::Client

use REST::Client; my $client = REST::Client->new(); $client->setHost('https://jira.hostname:PORT/jira/rest'); $client->request('post', '/auth/1/session', ['{ "username" : "myus +er", "password" : "mypass" }', undef]); print ($client->responseContent());

And now I'm trying a custom request with LWP

use LWP; use LWP::UserAgent; use HTTP::Request; use JSON; my $host = 'https://jira.hostname:PORT/jira/rest'; my $loginurl = '/auth/1/session'; my %credentials = ("username"=>"myuser", "password"=>"mypa +ss"); my $json = encode_json \%credentials; my $request = HTTP::Request->new('POST', $host.=$loginurl) +; $request -> header('Content-Type'=>'application/json'); $request -> content($json); my $browser = LWP::UserAgent->new; $browser -> agent('Mozilla/5.0'); $browser -> protocols_allowed(['https']); my $response = $browser->request($request); if($response->is_success){ print $response->decoded_content; } else { die $response->status_line; };

All of them are giving me the same or a similar response:

500 Can't connect to jira.hostname:PORT Bad file descriptor at C:/myperl/perl/vendor/lib/LWP/Protocol/http.pm +line 47. at jiratest.pl line 28.

I think that the LWP lib might be broken somehow, but I already tried upgrading and reinstalling via CPAN and still got no response. The code from the LWP/Protocol/http.pm file is:

sub _new_socket { my($self, $host, $port, $timeout) = @_; # IPv6 literal IP address should be [bracketed] to remove # ambiguity between ip address and port number. if ( ($host =~ /:/) && ($host !~ /^\[/) ) { $host = "[$host]"; } local($^W) = 0; # IO::Socket::INET can be noisy my $sock = $self->socket_class->new(PeerAddr => $host, PeerPort => $port, LocalAddr => $self->{ua}{local_address}, Proto => 'tcp', Timeout => $timeout, KeepAlive => !!$self->{ua}{conn_cache}, SendTE => 1, $self->_extra_sock_opts($host, $port), ); unless ($sock) { # IO::Socket::INET leaves additional error messages in $@ my $status = "Can't connect to $host:$port"; if ($@ =~ /\bconnect: (.*)/ || $@ =~ /\b(Bad hostname)\b/ || $@ =~ /\b(certificate verify failed)\b/ || $@ =~ /\b(Crypt-SSLeay can't verify hostnames)\b/ ) { $status .= " ($1)"; } die "$status\n\n$@"; # this is the mentioned "line 47" } # perl 5.005's IO::Socket does not have the blocking method. eval { $sock->blocking(0); }; $sock; }

I really hoped I could fix this myself as generally solving issues yourself is a great way to learn about the language, but I really don't know what to do anymore. It has to be a problem on the client side, because the server is responding as regular when I'm using JavaScript. Any help would be greatly appreciated!
P.S: I've always used  use strict; use warnings; as well, so I don't think it has something to do with that


EDIT: Corion's comment was right, it was a proxy issue as well as a SSL-Certificate issue.

Thank you for your help Perl Monks!


In reply to Can't get a server response from LWP Request by ddominnik

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.