Code Monkey home page Code Monkey logo

php-restclient's People

Contributors

baptistejamin avatar h4ng3r avatar magelogger avatar marekskopal avatar mmolle-nelo avatar ocjojo avatar tcdent avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

php-restclient's Issues

How do i include Authorization header?

Hi Travis,
I m trying to use the RESTClient developed by you. Could you please inform if I am doing the right thing below (esp while including Authorization header):

$api = new RestClient(array(
     'base_url' => "https://api2.this.com/crm/v1/rest", 
      'format' => "xml",
      'Authorization' => 'Basic '.base64_encode("6C135EDF-C37C-4039-AEF3-5DFC079F9E6A:Statementone:sonedemo"),
      'username'=> 'Statementone',
      'password' => 'sonedemo',
  ));

Can't install php-restclient with composer : Man in the middle attack warning

Hi,
I couldn't install php-restclient using composer. Composer would always abort with the following exception message:

[Composer\RepositoryRepositorySecurityException]                                                                              
The contents of http://packagist.org/p/tcdent php-restclient%24647cf0d27ae7f67bbfe60303644cfcf7c01cd45ec4f817b52f9593af108320b0.json do not match its signature.
This should indicate a man-in-the-middle attack. Try running composer again and report this if you think it is a mistake.

Actually something wrong with the signature?

Thanks, Zangue

Implementation in yii2

I would like to know if you have any way to implement your library in yii2 framework, since you review a how to, where they use it but do not explain how to integrate it into the framework

Removing extension form URI

Hey,

I'm using your REST client to request an API with an old fashioned router, which does not really like the fact that the router appends '.json' at the end of the URI.

I use this simple code :

// Initialize the REST Client
$params = [
    'format' => 'json',
    'headers' => [
        'Content-Type' => 'application/json'
    ]
];

$this->credentials = $parameters["credentials"];

if(!empty($this->credentials["username"]) && !empty($this->credentials["password"])){
    $params = array_merge($params, $this->credentials);
}

$this->uri = $parameters['uri'];
$this->api = new RestClient($params);

// Call the API ($this->uri : http://localhost:8001)
$result = $this->api->get($this->uri . "/jobs");

Is there a way to remove the '.json' appended at the end of the URI ?

PHP 8.1 incompatibility

Hey!

Magento 2 uses the tcdent/php-restclient package and the new version (2.4.4) has a lot of PHP 8.1 incompatible issues:

Deprecated: Return type of RestClient::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/html/vendor/tcdent/php-restclient/restclient.php on line 66
PHP Deprecated:  Return type of RestClient::next() should either be compatible with Iterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/html/vendor/tcdent/php-restclient/restclient.php on line 74

Deprecated: Return type of RestClient::next() should either be compatible with Iterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/html/vendor/tcdent/php-restclient/restclient.php on line 74
PHP Deprecated:  Return type of RestClient::key() should either be compatible with Iterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/html/vendor/tcdent/php-restclient/restclient.php on line 70

Deprecated: Return type of RestClient::key() should either be compatible with Iterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/html/vendor/tcdent/php-restclient/restclient.php on line 70
PHP Deprecated:  Return type of RestClient::valid() should either be compatible with Iterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/html/vendor/tcdent/php-restclient/restclient.php on line 78

Deprecated: Return type of RestClient::valid() should either be compatible with Iterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/html/vendor/tcdent/php-restclient/restclient.php on line 78
PHP Deprecated:  Return type of RestClient::rewind() should either be compatible with Iterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/html/vendor/tcdent/php-restclient/restclient.php on line 61

Deprecated: Return type of RestClient::rewind() should either be compatible with Iterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/html/vendor/tcdent/php-restclient/restclient.php on line 61
PHP Deprecated:  Return type of RestClient::offsetExists($key) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/html/vendor/tcdent/php-restclient/restclient.php on line 84

Deprecated: Return type of RestClient::offsetExists($key) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/html/vendor/tcdent/php-restclient/restclient.php on line 84
PHP Deprecated:  Return type of RestClient::offsetGet($key) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/html/vendor/tcdent/php-restclient/restclient.php on line 90

Deprecated: Return type of RestClient::offsetGet($key) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/html/vendor/tcdent/php-restclient/restclient.php on line 90
PHP Deprecated:  Return type of RestClient::offsetSet($key, $value) should either be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/html/vendor/tcdent/php-restclient/restclient.php on line 99

Deprecated: Return type of RestClient::offsetSet($key, $value) should either be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/html/vendor/tcdent/php-restclient/restclient.php on line 99
PHP Deprecated:  Return type of RestClient::offsetUnset($key) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/html/vendor/tcdent/php-restclient/restclient.php on line 103

Deprecated: Return type of RestClient::offsetUnset($key) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/html/vendor/tcdent/php-restclient/restclient.php on line 103

Patch

Can i use patch verb?

Empty headers

Hi

lines 146 to 148 :

supposing
$client->options['headers'] is null
$headers is an array
then
array_merge returns null
$headers are not sent

Cheers

Caching REST response

Hey,

It is possible / planned to cache content received into a file or with the Memcached PHP mecanism ?

Repeat parameter key

Is it possible to post a repeatable parameter key like this?

{ "repeatableKey" : { "bla":"bla", "bla":"bla", }, "repeatableKey" : { "bla":"bla", "bla":"bla", }, "repeatableKey" : { "bla":"bla", "bla":"bla", } }

Regards,
Bas

Need support

i'm newbie in PHP. I use your restclient to request as below:


<?php

require 'restclient.php';

		$api = new RestClient();
		$result = $api->get("https://api.github.com/repos/phatls/CallCenter_Customer/issues?state=all");
		if($result->info->http_code == 200)
		    echo ($result->response);
		else 
			echo "false";

?>

It works greatly. But with:

<?php

require 'restclient.php';
		$api = new RestClient();
		$result = $api->get("http://beka.vn/api/BkMobileLogin/GetGroup/phat.ls");
		if($result->info->http_code == 200)
		     echo ($result->response);
		 else 
			echo "false";

?>

It returns false. Please help me if you don't have any inconvenient.
thanks

Post Json format

There is POST method that has not been working.

This is sample CURL example at the service.

{"email": "[email protected]", "items": [{ "name": "api Name", "quantity": 10, "unit_price": 2}, { "name": "api 2", "quantity": "4", "unit_price": 3 }] 

}

Have the tried the following.

$data = array(
        'email' => '[email protected]', 
        );
$data['items'] = array(
        'name' => 'fruits', 'quantity' => 4,
         'unit_price' => 7,
        );

$data2 = array(
            'email' => '[email protected]', 'currency' => 'USD',
            'country' => 'US', 'billing_first_name' => 'John',
            // 'items' => '',
            'items' =>  array(
            0 => array(
                'unit_price' => 10.00, 
                'name' => 'item1',
                'quantity' => 15
                ),
            1 => array(
                'unit_price' => 34.00, 
                'name' => 'item2', 
                'quantity' => 42
                )
            )

            );

$result = $api->post('invoice/', $data,
            array('Content-Type' => 'application/json'));

The service just accepts email, and ignores items.

The requested URL was rejected. Please consult with your administrator

All POST type queries to some private APIs return the result as "The requested URL was rejected. Please consult with your administrator". I found that the following section on line 151 caused this:

$curlopt[CURLOPT_HTTPHEADER][] = sprintf("%s:%s", $key, $value);

Putting a space after the semicolon fixes the problem.

$curlopt[CURLOPT_HTTPHEADER][] = sprintf("%s: %s", $key, $value);

Retrieve Body Information

Hello , how I can't retrieve the only the body response?
I don't find how to do in your Documentation.

Error SSL certificate problem: self signed certificate

Hi, I want to know how I can avoid this error.

SSL certificate problem: self signed certificate

Currently the API that is a consumer used by HTTPS but the SSL certificate is not yet valid, I want to be able to use its library without having a valid SSL.

How could I solve the error?

Metaclass for API definitions

RestClient is dynamic and does not conform to API specs. Provide an interface to defining API methods for documentation and validation of client implementations.

Add a curl debug output

It'd be great if you could, once the request is totally built, and right before performing it, mark a flag to output the curl as in cli to be able to debug & compare... just saying :D

parse_response has problems with 100 Continue

First, I love the class you created. It saved me a lot of time creating my own custom clients. I noticed a problem working with the AirWatch REST API. The API return headers such as "200 Continue" when data sets are abnormally large or truncated. So, you end up with two HTTP headers. The two headers are separated by line break.

HTTP/1.1 100 Continue

HTTP/1.1 200 OK
Cache-Control: no-cache
Pragma: no-cache
Content-Type: application/json; charset=utf-8
Expires: -1
Server: Microsoft-IIS/7.5

The result of this is that you never get the response parsed correctly. I did a bit of a hack to check for a 200 code and then skip it and the next line. I'm sure this could be done better.

public function parse_response($response){
    $headers = array();
    $http_ver = strtok($response, "\n");

    // Check for 100 Continue header followed by 200 OK header
    if (preg_match("/^HTTP\/[0-9]\.[0-9] 100 Continue/", $http_ver)) {
        $this->continue = true;
        // Skip blank line and get next http
        $line = strtok("\n");
        $http_ver = strtok("\n");
    }

    while($line = strtok("\n")){
        if(strlen(trim($line)) == 0) break;

        list($key, $value) = explode(':', $line, 2);
        $key = trim(strtolower(str_replace('-', '_', $key)));
        $value = trim($value);
        if(empty($headers[$key]))
            $headers[$key] = $value;
        elseif(is_array($headers[$key]))
            $headers[$key][] = $value;
        else
            $headers[$key] = array($headers[$key], $value);
    }

    $this->headers = (object) $headers;
    $this->response = trim(strtok(""));
}

Wiki permissions opened to everyone ?

Hey,

I'm not really sure about this, but I don't think this Java REST GUI is really related to your PHP library.
I looked at your wiki and it seems that everyone is able to write pages to this Wiki. Maybe should you remove those permissions :)

Error passing file in parameters

Hi,
I'm getting an error when I try to send a PDF file as a parameter with other information.
This problem disappears when I use raw cURL.

Cheers.

Complete typing

We currently have incomplete typing in order to support older versions of PHP. Determine lowest version cutoff to support all type features & users.

"format" gets always appended to the URL

Hi,

If you set format eg. to "json", the execute function always appends it as file extension to the url because of this:
if($client->options['format']) $client->url .= '.'.$client->options['format'];

There should be an option to disable that. In my case, the service doesn't accept any file extension. If I leave format empty I get "Response format could not be determined.", which indicates that get_response_format couldn't auto detect the response format. Even if it would auto detect, I wouldn't want to rely on that, because the service response headers might change although the response content is still the same.

Just a boolean option and a check in the if statement above should fix that.

parse_response - problems parsing HTTP 100 Continue with extra header info

Thanks for creating this very helpful class!

This is a build on issue #14.

I need to connect to an API that is responding with HTML header information in between the HTTP 100 Continue and the HTTP 200 OK response lines. This results in the $api->header info being incomplete, the $api->response field containing header information and my xml decoder failing for multiple reasons.
I've recommended a potential fix for this issue. Could the parse_response method be updated to handle this peculiar case?

-- Problematic Header --
HTTP/1.1 100 Continue
Via: 1.1 ID-0000605166710030 uproxy-3

HTTP/1.1 200 OK
Date: Wed, 24 Oct 2018 18:20:07 GMT
Accept-Ranges: bytes
Server: Apache
Content-Type: text/xml
Transfer-Encoding: chunked
Connection: close
Via: 1.1 ID-0000605166710030 uproxy-2

-- Potential Fix -- see 3 lines with $http_continue

    public function parse_response($response){
        $headers = [];
        $this->response_status_lines = [];
        $http_continue=false; 
        $line = strtok($response, "\n");
        do {
            if(strlen(trim($line)) == 0){
                // Since we tokenize on \n, use the remaining \r to detect empty lines.
                if((count($headers) > 0) && (!$http_continue)) break; // Must be the newline after headers, move on to response body
            }
            elseif(strpos($line, 'HTTP') === 0){
                // One or more HTTP status lines
                $this->response_status_lines[] = trim($line);
                //HANDLE HTTP 100 Continue 
                $http_continue = (strpos($line, '100 Continue') !== false );
            }
            

$url as property of the class

Hi,

I noticed that $url is not a defined property of the RestClient class. However it is used implicitly e.g. here
Is there a reason for this? I will gladly create a pull request, if it is not.

The reason I noticed is, that I extend the RestClient class and overwrite the __set and __get functions, which are being called when setting the url. I could also just test for the property name and make an exception in my code. Just curious, why it is not defined explicitly, while all other properties are.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.