HTTP method is not allowed for the requested resource

Using the REST API resources, http://localhost:8095/crowd/rest/usermanagement/latest/user?username=USERNAME  we are able to receive the XML response successfully. The <href> links for <attributes> work without any HTTP error, but not for <password> it produces an HTTP 405 Error code having description :The specified HTTP method is not allowed for the requested resource.

We also tried the http://localhost:8095/crowd/rest/usermanagement/latest/authentication?username=USERNAME but got same error.

How to access the <password> for authentication purposes from XML response ?


2 answers

1 accepted

1 vote
Accepted answer

Hi Karthikayan, 

The code 405 means that the method used is incorrect. So, maybe, you might be using GET instead of POST, and the password attribute just works with POST method, as you can see in this link in the session User Authentication  Resource. 

Given that, you can test the command bellow for we see if you can get the return as you expect.

 

curl -X POST -H "Accept: application/json" -H "Content-Type: application/json" -u appname:apppassword -d '{"value":"password"}' http://localhost:8095/crowd/rest/usermanagement/1/authentication?username=USERNAME

Please let me know if it worked. 

 

Cheers, 

Renato Rudnicki

 

Thank you Renato ,

This command worked perfectly on terminal. But produced HTTP 400 error for Content- type :XML.
Also , How can this POST request be embed with PHP-curl script to authenticate a user ?

I am attaching the code snippet for review.

Looking forward to your reply.

 

&lt;?php
 if ($_SERVER['REQUEST_METHOD'] == 'POST') 
 {
 $xml = "&lt;?xml version='1.0' encoding='UTF-8'?&gt;";
 $xml .= "&lt;request&gt;";

 foreach ($_POST as $key =&gt; $val) {
 $xml .= "&lt;".$key."&gt;". $val ."&lt;/".$key."&gt;";
 }
 $xml .= "&lt;username&gt;USERNAME&lt;/username&gt;";
 $xml .= "&lt;password&gt;PASSWORD&lt;/password&gt;";
 $xml .= "&lt;/request&gt;"; 

 echo "&lt;br/&gt;" . $xml . "&lt;br/&gt;&lt;br/&gt;";

 $ch = curl_init();
 curl_setopt($ch, CURLOPT_URL, 'http://localhost:8095/crowd/rest/usermanagement/latest/authentication?username=USERNAME');
 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
 curl_setopt($ch, CURLOPT_HEADER, 1);
 curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/xml'));
 curl_setopt($ch, CURLOPT_POST, 1);
 curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);

 $output = curl_exec($ch);
 curl_close($ch);

 echo '&lt;pre&gt;';
 echo htmlspecialchars(print_r($output, true));
 echo '&lt;/pre&gt;'; 
 }
 ?&gt;

You’re welcome Karthikayan, I’m glad that I could help you. Let me try again :) A good way for you do your own troubleshoot about http errors is try to understand what means the HTTP codes. In this case, 400 error means problem with the syntax. You can get a full list in this link: http://en.wikipedia.org/wiki/List_of_HTTP_status_codes . I’m not a developer, but having a look in your php script, I believe that you are in the right way about the code (you just need to find where is the syntax error in your script). However, I’m afraid my PHP skills aren’t enough to help you about the POST request be embed in the script :( but let’s see if someone more can help us with it. If there’s anyone thing that I can do for you, feel free to ask :) Chers, Renato Rudnicki

Thank you Renato , I figured solution for this :)

Hi karthikayan, I'm glad to hear it :) If you don't mind, could you share the solution here ? Maybe it can be useful to another person in the future. All the best, Renato Rudnicki

Love it when people ask for help and then leave with the comment "I figured solution for this :)". Somehow selfish.

Like 1 person likes this

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Wednesday in Jira

Make your Atlassian Cloud products more secure: our NEW admin security guide

Hey admins! I’m Dave, Principal Product Manager here at Atlassian working on our cloud platform and security products. Cloud security is a moving target. As you adopt more products, employees consta...

61 views 0 3
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you