title: Why do I get "405: Method Not Allowed" when I send a POST request with Perl's REST::Client, but not with Perl's LWP::UserAgent or Python?
body: <p>When I send a POST request with Perl's <a href="https://metacpan.org/pod/REST::Client" rel="nofollow"><code>REST::Client</code></a>, I get the following response:</p>
  
  <pre class="lang-none prettyprint-override"><code>405: Method Not Allowed
  </code></pre>
  
  <p>However, when I send a POST request to the same URL with Perl's <a href="https://metacpan.org/pod/LWP::UserAgent" rel="nofollow"><code>LWP::UserAgent</code></a> or Python's <code>Requests</code>, I get a "success" response. GET requests work with both <code>REST::Client</code> and Python.</p>
  
  <p>How can I fix this?</p>
  
  <hr>
  
  <p>Here's the code that uses <code>REST::Client</code> (returns HTTP 405):</p>
  
  <pre><code>use REST::Client;
  use JSON;
  $header = {
      'Auth' =&gt; '04211b77df',
      'Accept' =&gt; 'application/json',
      'Content-type' =&gt; 'application/json'
  };
  
  %body = (
      'sid' =&gt; '001',
      'pid' =&gt; 'c7b3d83',
      'file' =&gt; [
          {
              'name' =&gt; 'file1.txt',
              'location' =&gt; 'folderA'
          },
          {
              'name' =&gt; 'file2.txt',
              'location' =&gt; 'folderB'
          }
      ]
  );
  
  $client = REST::Client-&gt;new();
  $client-&gt;POST('URL', encode_json(\%body), $header);
  </code></pre>
  
  <p>Here's the code that uses <code>LWP::UserAgent</code> (returns HTTP 200):</p>
  
  <pre><code>#!/use/bin/perl -w
  use strict;
  use LWP::UserAgent;
  use Data::Dumper;
  use JSON;
  
  my $ua = LWP::UserAgent-&gt;new; 
  my $req = HTTP::Request-&gt;new(POST =&gt; 'URL');
  
  $req-&gt;header('Auth' =&gt; '04211b77df');
  $req-&gt;header('Content-type' =&gt; 'application/json');
  $req-&gt;header('Accept' =&gt; 'application/json');
  
  my %body = (
      'sid' =&gt; '001',
      'pid' =&gt; 'c7b3d83',
      'file' =&gt; [
          {
              'name' =&gt; 'file1.txt',
              'location' =&gt; 'folderA'
          },
          {
              'name' =&gt; 'file2.txt',
              'location' =&gt; 'folderB'
          }
      ]
  );
  $req-&gt;content(encode_json(\%body));
  $ua-&gt;request($req);
  </code></pre>
  
  <p>Here's the Python code (returns HTTP 200):</p>
  
  <pre><code>import requests, json, sys
  headers = {
      'Auth': '04211b77df'
      'Accept': 'application/json'
      'Content-type': 'application/json'
  }
  data={
      'sid': '001',
      'pid': 'c7b3d83',
      'file': [
          {
              'name': 'file1.txt',
              'location': 'folderA'
          },
          {
              'name': 'file2.txt',
              'location': 'folderB'
          }
      ]
  }
  
  requests.request('POST', 'URL', data=data, headers=headers)
  </code></pre>