# PUT request giving error "405 Method Not Allowed"

**URL:** <https://discourse.slimframework.com/t/put-request-giving-error-405-method-not-allowed/268>\
**Category:** Questions\
**Created:** [May 17, 2016, 12:26pm UTC](https://discourse.slimframework.com/t/put-request-giving-error-405-method-not-allowed/268 "2016-05-17T12:26:43Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![kamran\_bhatti58](https://avatars.discourse-cdn.com/v4/letter/k/439d5e/32.png) [@kamran\_bhatti58](https://discourse.slimframework.com/u/kamran_bhatti58)\
**Post date:** [May 17, 2016, 12:26pm UTC](https://discourse.slimframework.com/t/put-request-giving-error-405-method-not-allowed/268/1 "2016-05-17T12:26:43Z")

</div>

I am building a rest webservice using SLIM which is working fine with GET and POST method but when i tried to Request a PUT method. It is giving me error “405 Method Not Allowed”. i don’t know what is the problem.  
Here is my code:  
`$app->put('/user/:id', function($user_id) use ($app) { echo 'done'; });`

Here is my .htaccess:  
`RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ index.php [QSA,L]`

Need Help! My hosting is Godaddy

---

<div class="post-metadata">

**Author:** ![JoeBengalen](https://avatars.discourse-cdn.com/v4/letter/j/b5e925/32.png) [@JoeBengalen](https://discourse.slimframework.com/u/JoeBengalen)\
**Post date:** [May 17, 2016, 12:30pm UTC](https://discourse.slimframework.com/t/put-request-giving-error-405-method-not-allowed/268/2 "2016-05-17T12:30:02Z")

</div>

How are you sending the request? What is the response you get? Response should contain a list of allowed methods

---

<div class="post-metadata">

**Author:** ![kamran\_bhatti58](https://avatars.discourse-cdn.com/v4/letter/k/439d5e/32.png) [@kamran\_bhatti58](https://discourse.slimframework.com/u/kamran_bhatti58)\
**Post date:** [May 17, 2016, 12:34pm UTC](https://discourse.slimframework.com/t/put-request-giving-error-405-method-not-allowed/268/3 "2016-05-17T12:34:39Z")

</div>

I am using **Postman** to check my webservice. FYI **Get** and **Post** are working fine. But whenever i make a **Put** request. Postman shows me error like this:  
`  
  
405 Method Not Allowed  
  
\<!–[if lte IE 6]\>

# Method Not Allowed
  
The HTTP verb used to access this page is not allowed.  

* * *
  
  
Web Server at immacbytes.com `

---

<div class="post-metadata">

**Author:** ![JoeBengalen](https://avatars.discourse-cdn.com/v4/letter/j/b5e925/32.png) [@JoeBengalen](https://discourse.slimframework.com/u/JoeBengalen)\
**Post date:** [May 17, 2016, 12:36pm UTC](https://discourse.slimframework.com/t/put-request-giving-error-405-method-not-allowed/268/4 "2016-05-17T12:36:31Z")

</div>

That does not look like a response from Slim. Could it be that the webserver is blocking PUT and Slim is not even hit?

---

<div class="post-metadata">

**Author:** ![kamran\_bhatti58](https://avatars.discourse-cdn.com/v4/letter/k/439d5e/32.png) [@kamran\_bhatti58](https://discourse.slimframework.com/u/kamran_bhatti58)\
**Post date:** [May 17, 2016, 12:38pm UTC](https://discourse.slimframework.com/t/put-request-giving-error-405-method-not-allowed/268/5 "2016-05-17T12:38:27Z")

</div>

Yes! webserver is blocking **Put** and that’s why **Slim** is not even hitting **Put** method.

---

<div class="post-metadata">

**Author:** ![JoeBengalen](https://avatars.discourse-cdn.com/v4/letter/j/b5e925/32.png) [@JoeBengalen](https://discourse.slimframework.com/u/JoeBengalen)\
**Post date:** [May 17, 2016, 12:40pm UTC](https://discourse.slimframework.com/t/put-request-giving-error-405-method-not-allowed/268/6 "2016-05-17T12:40:45Z")

</div>

Well, then search for some documentation at GoDaddy on how to allow PUT requests.

---

<div class="post-metadata">

**Author:** ![kamran\_bhatti58](https://avatars.discourse-cdn.com/v4/letter/k/439d5e/32.png) [@kamran\_bhatti58](https://discourse.slimframework.com/u/kamran_bhatti58)\
**Post date:** [May 17, 2016, 12:41pm UTC](https://discourse.slimframework.com/t/put-request-giving-error-405-method-not-allowed/268/7 "2016-05-17T12:41:41Z")

</div>

Ok, Thanks for your response.

---

<div class="post-metadata">

**Author:** ![llvdl](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/llvdl/32/78_2.png) [@llvdl](https://discourse.slimframework.com/u/llvdl)\
**Post date:** [May 17, 2016, 8:33pm UTC](https://discourse.slimframework.com/t/put-request-giving-error-405-method-not-allowed/268/8 "2016-05-17T20:33:11Z")

</div>

According to the [docs](http://www.slimframework.com/docs/objects/request.html#the-request-method), you can also specify the request method using the `_METHOD` query string parameter.

If your hosting provider supports `POST`, but not `PUT`, you could try adding `_METHOD=PUT` to your POST data.

---

<div class="post-metadata">

**Author:** ![kamran\_bhatti58](https://avatars.discourse-cdn.com/v4/letter/k/439d5e/32.png) [@kamran\_bhatti58](https://discourse.slimframework.com/u/kamran_bhatti58)\
**Post date:** [May 18, 2016, 10:16pm UTC](https://discourse.slimframework.com/t/put-request-giving-error-405-method-not-allowed/268/9 "2016-05-18T22:16:26Z")

</div>

Thanks for response. Can you please write a single example here?  
e.g:  
`$app->put('/user/:id', function($user_id) use ($app) { echo 'done'; });`  
so that it would make me more clear.

---

<div class="post-metadata">

**Author:** ![llvdl](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/llvdl/32/78_2.png) [@llvdl](https://discourse.slimframework.com/u/llvdl)\
**Post date:** [May 19, 2016, 8:07pm UTC](https://discourse.slimframework.com/t/put-request-giving-error-405-method-not-allowed/268/10 "2016-05-19T20:07:22Z")

</div>

Here is an example for the route that matches your PUT request:

```
$app->put('/user/{user_id}', function($request, $response, $args) {
    // the url argument is stored in $args 
    $userId = $args['user_id'];

    // parsing the form data
    $data = $request->getParsedBody();
    $name = $data['name'];

    // writing a string as output, normally you would some sort of view
    $response->getBody()->write(
        sprintf('PUT: user id=%d, name=%s', $userId, htmlspecialchars($name))
    );
});

```

You can submit a request that matches the PUT route using a POST request, by adding \_METHOD=PUT in your post data, as I mentioned. Using an HTML form this would look something like:

```
<form action="/user/5" method="POST">
    <-- indication for Slim that this should be interpreted as a PUT request -->
    <input type="hidden" name="_METHOD" value="PUT"/>

    <!-- more form data -->
    <p><label>Name:</label> <input type="text" name="name"/></p>

    <p><button type="submit">Submit form</button></p>
</form>

```

Hope that helps.

---

<div class="post-metadata">

**Author:** ![kamran\_bhatti58](https://avatars.discourse-cdn.com/v4/letter/k/439d5e/32.png) [@kamran\_bhatti58](https://discourse.slimframework.com/u/kamran_bhatti58)\
**Post date:** [May 24, 2016, 7:39pm UTC](https://discourse.slimframework.com/t/put-request-giving-error-405-method-not-allowed/268/11 "2016-05-24T19:39:51Z")

</div>

Thanks @llvdl , But I am requesting from Android device(Java). How to do this request in java?

---

<div class="post-metadata">

**Author:** ![kamran\_bhatti58](https://avatars.discourse-cdn.com/v4/letter/k/439d5e/32.png) [@kamran\_bhatti58](https://discourse.slimframework.com/u/kamran_bhatti58)\
**Post date:** [May 24, 2016, 7:41pm UTC](https://discourse.slimframework.com/t/put-request-giving-error-405-method-not-allowed/268/12 "2016-05-24T19:41:47Z")

</div>

Sorry @JoeBengalen Without using SLIM, I can update a column with simple Query. But Slim “PUT” method is not working and I am continuously getting **Method Not Allowed** Error. Need Help!

---

<div class="post-metadata">

**Author:** ![JoeBengalen](https://avatars.discourse-cdn.com/v4/letter/j/b5e925/32.png) [@JoeBengalen](https://discourse.slimframework.com/u/JoeBengalen)\
**Post date:** [May 25, 2016, 3:03pm UTC](https://discourse.slimframework.com/t/put-request-giving-error-405-method-not-allowed/268/13 "2016-05-25T15:03:24Z")

</div>

Can you retrieve a PUT request without using Slim? Or are you using POST to update the column with simple Query

---

<div class="post-metadata">

**Author:** ![kamran\_bhatti58](https://avatars.discourse-cdn.com/v4/letter/k/439d5e/32.png) [@kamran\_bhatti58](https://discourse.slimframework.com/u/kamran_bhatti58)\
**Post date:** [May 25, 2016, 10:48pm UTC](https://discourse.slimframework.com/t/put-request-giving-error-405-method-not-allowed/268/14 "2016-05-25T22:48:50Z")

</div>

I am doing a update using PUT request as follows:

```
$app->put('/user/:id', function($name) use ($app) 
{
     global $app;
     verifyRequiredParams(array('id'));
     $id= $app->request->put('id');
     $db = new DbHandler();
    $response = $db->updUser($id, $name);
    echoRespnse(200, $response);
});

```

And in DbHandler() function, I am doing this:

```
 public function updUser($id, $name) 
 {
      $response = array();
  $db = new DbConnect();
      $conn = $db->connect();
  $sql = "UPDATE table SET name = ? WHERE id = ?";
      $stmt = sqlsrv_prepare( $conn, $sql, array( &$name, &$id));
      if (sqlsrv_execute( $stmt ) === true)
      {
          // User successfully updated
          $response["error"] = false;
          $response["message"] = 'updated success';
        } 
	else 
	{
            // Failed to update user
            $response["error"] = true;
            $response["message"] = "Failed to update ";
         } 
        return $response;
}

```

But whenever I access this function, it returns me **405 Method Not Allowed** Error.  
If I do POST requests, or GET request with the same methods, then all works fine!

---

<div class="post-metadata">

**Author:** ![llvdl](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/llvdl/32/78_2.png) [@llvdl](https://discourse.slimframework.com/u/llvdl)\
**Post date:** [May 31, 2016, 10:41am UTC](https://discourse.slimframework.com/t/put-request-giving-error-405-method-not-allowed/268/15 "2016-05-31T10:41:46Z")

</div>

How are you making the PUT request? Can show some code or a screen shot (if using Postman)?
