php-hmac-rest-api icon indicating copy to clipboard operation
php-hmac-rest-api copied to clipboard

Problem with GET, PUT, DELETE requests

Open danipolo opened this issue 9 years ago • 9 comments

Hi fellas!

In first instance, thanks for your code. It's helping me a lot building an API.

In client-connect.php, when I make a POST request, it work's ok and return me data.

When I try to make a GET, DELETE or PUT request from the client, I get that error:

$ php client-connect.php

Request: 
DELETE /nodes/mikrotik HTTP/1.1
Host: vpn.testdomain.com
Accept: */*
API_ID: 1
API_TIME: 1445949810
API_HASH: 7c6a4db71e9991c97b871eeecb5f4ac95163fd868f4f5c87cfeb2414068d0314
Content-Length: 510
Expect: 100-continue
Content-Type: multipart/form-data; boundary=------------------------8d099346432455ca


Response:
HTTP/1.1 100 Continue

HTTP/1.1 401 Unauthorized
Server: nginx/1.6.2
Date: Tue, 27 Oct 2015 12:43:29 GMT
Content-Type: text/html; charset=UTF-8
Transfer-Encoding: chunked
Connection: keep-alive

Access denied 

I'm just uncommenting the line in the client:

curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
curl_setopt($ch, CURLOPT_URL, $host);
// curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_HEADER, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLINFO_HEADER_OUT, TRUE);

I'm not sure what more I need to do but I cant send any other request than POST. Maybe it's a dumb question but I really tried lot of things before asking...

Anybody can helps?

Thanks!

danipolo avatar Oct 27 '15 12:10 danipolo

Can you post your routes file (php-hmac-rest-api/app/config/routes.php)

jeteokeeffe avatar Oct 27 '15 15:10 jeteokeeffe

sure:

<?php

/**
 * @author Jete O'Keeffe
 * @version 1.0
 * @link http://docs.phalconphp.com/en/latest/reference/micro.html#defining-routes
 * @eg.
 */

// 
// NodesController 
//

$routes[] = [
    'method' => 'post', 
    'route' => '/nodes/{id}', 
    'handler' => ['Controllers\NodesController', 'addNode']
];


$routes[] = [
    'method' => 'get', 
    'route' => '/nodes/{id}', 
    'handler' => ['Controllers\NodesController', 'getNode']
];

$routes[] = [
    'method' => 'put', 
    'route' => '/nodes/{id}', 
    'handler' => ['Controllers\NodesController', 'updateNode']
];

$routes[] = [
    'method' => 'delete', 
    'route' => '/nodes/{id}', 
    'handler' => ['Controllers\NodesController', 'deleteNode']
];

// 
// Run in Node
//

$routes[] = [
    'method' => 'post', 
    'route' => '/run/{id}', 
    'handler' => ['Controllers\RunController', 'runInNode']
];


// ExampleController
$routes[] = [
    'method' => 'post', 
    'route' => '/ping', 
    'handler' => ['Controllers\ExampleController', 'pingAction']
];

// $routes[] = [
//  'method' => 'post', 
//  'route' => '/test/{id}', 
//  'handler' => ['Controllers\ExampleController', 'testAction']
// ];

// $routes[] = [
//  'method' => 'post', 
//  'route' => '/skip/{name}', 
//  'handler' => ['Controllers\ExampleController', 'skipAction'],
//     'authentication' => FALSE
// ];

return $routes;

danipolo avatar Oct 27 '15 17:10 danipolo

anything wrong? I'm asking in StackOverflow but not response there...

danipolo avatar Oct 28 '15 11:10 danipolo

Looks good. I'll try to add an an example put in the client tonight

Sent on the new Sprint Network from my Samsung Galaxy S®4

-------- Original message -------- From: Dani Polo [email protected] Date: 10/28/2015 7:23 AM (GMT-05:00) To: jeteokeeffe/php-hmac-rest-api [email protected] Cc: J [email protected] Subject: Re: [php-hmac-rest-api] Problem with GET, PUT, DELETE requests (#24)

anything wrong? I'm asking in StackOverflow but not response there...

— Reply to this email directly or view it on GitHub.

jeteokeeffe avatar Oct 28 '15 17:10 jeteokeeffe

Million thanks! I will wait for sure! thank you very much!

danipolo avatar Oct 28 '15 17:10 danipolo

pull the latest.

in client-connect.php, find the $method and change it to "GET" or "PUT" or "DELETE". i just tested it and its working

jeteokeeffe avatar Oct 28 '15 23:10 jeteokeeffe

I'm sure right now, not having success. I download the whole project again and try it. Just having problems with GET. The client seems it making a POST request (not GET). Any ideas?

danipolo avatar Oct 29 '15 13:10 danipolo

I wrote the client as a quick and dirty example, not as way to cover all cases. Anyway, I fixed the client to send proper get requests but the get on the actual micro framework seems broken. I'll have to dig more into it.

 On Thursday, October 29, 2015 9:48 AM, Dani Polo <[email protected]> wrote:

I'm sure right now, not having success. I download the whole project again and try it. Just having problems with GET. The client seems it making a POST request (not GET). Any ideas?— Reply to this email directly or view it on GitHub.

jeteokeeffe avatar Oct 29 '15 14:10 jeteokeeffe

Thanks! (I was starting to feel VERY dumb)

I think I found something: When you remove the $data array in the client.php, it works good. When I add the $data array, it returns me Access Denied. Thank you so much for your fast reply :100:

danipolo avatar Oct 29 '15 15:10 danipolo