Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

HTTP method is not allowed for the requested resource

Karthikayan Visvanathan September 11, 2014

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
Answer accepted
rrudnicki
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 11, 2014

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

 

0 votes
Karthikayan Visvanathan September 12, 2014

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;
rrudnicki
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 14, 2014

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

Karthikayan Visvanathan September 16, 2014

Thank you Renato , I figured solution for this :)

rrudnicki
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 16, 2014

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

Lars Niestrad January 4, 2018

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

Like # people like this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events