Giter Site home page Giter Site logo

php-curl-class / php-curl-class Goto Github PK

View Code? Open in Web Editor NEW
3.2K 3.2K 827.0 2.6 MB

PHP Curl Class makes it easy to send HTTP requests and integrate with web APIs

Home Page: https://www.phpcurlclass.com/

License: The Unlicense

PHP 91.76% Shell 4.41% Python 1.77% Dockerfile 0.89% Hack 1.12% JavaScript 0.05%
api api-client class client curl framework http http-client http-proxy json php php-curl php-curl-library proxy requests restful web-scraper web-scraping web-service xml

php-curl-class's Introduction

PHP Curl Class: HTTP requests made easy

PHP Curl Class makes it easy to send HTTP requests and integrate with web APIs.

PHP Curl Class screencast



Installation

To install PHP Curl Class, run the following command:

composer require php-curl-class/php-curl-class

To install the latest commit version:

composer require php-curl-class/php-curl-class @dev

Installation instructions to use the composer command can be found on https://github.com/composer/composer.

Requirements

PHP Curl Class works with PHP 8.3, 8.2, 8.1, 8.0, 7.4, 7.3, 7.2, 7.1, and 7.0.

Quick Start and Examples

More examples are available under /examples.

require __DIR__ . '/vendor/autoload.php';

use Curl\Curl;

$curl = new Curl();
$curl->get('https://www.example.com/');

if ($curl->error) {
    echo 'Error: ' . $curl->errorMessage . "\n";
    $curl->diagnose();
} else {
    echo 'Response:' . "\n";
    var_dump($curl->response);
}
// https://www.example.com/search?q=keyword
$curl = new Curl();
$curl->get('https://www.example.com/search', [
    'q' => 'keyword',
]);
$curl = new Curl();
$curl->post('https://www.example.com/login/', [
    'username' => 'myusername',
    'password' => 'mypassword',
]);
$curl = new Curl();
$curl->setBasicAuthentication('username', 'password');
$curl->setUserAgent('MyUserAgent/0.0.1 (+https://www.example.com/bot.html)');
$curl->setReferrer('https://www.example.com/url?url=https%3A%2F%2Fwww.example.com%2F');
$curl->setHeader('X-Requested-With', 'XMLHttpRequest');
$curl->setCookie('key', 'value');
$curl->get('https://www.example.com/');

if ($curl->error) {
    echo 'Error: ' . $curl->errorMessage . "\n";
} else {
    echo 'Response:' . "\n";
    var_dump($curl->response);
}

var_dump($curl->requestHeaders);
var_dump($curl->responseHeaders);
$curl = new Curl();
$curl->setFollowLocation();
$curl->get('https://shortn.example.com/bHbVsP');
$curl = new Curl();
$curl->put('https://api.example.com/user/', [
    'first_name' => 'Zach',
    'last_name' => 'Borboa',
]);
$curl = new Curl();
$curl->patch('https://api.example.com/profile/', [
    'image' => '@path/to/file.jpg',
]);
$curl = new Curl();
$curl->patch('https://api.example.com/profile/', [
    'image' => new CURLFile('path/to/file.jpg'),
]);
$curl = new Curl();
$curl->delete('https://api.example.com/user/', [
    'id' => '1234',
]);
// Enable all supported encoding types and download a file.
$curl = new Curl();
$curl->setOpt(CURLOPT_ENCODING , '');
$curl->download('https://www.example.com/file.bin', '/tmp/myfile.bin');
// Case-insensitive access to headers.
$curl = new Curl();
$curl->download('https://www.example.com/image.png', '/tmp/myimage.png');
echo $curl->responseHeaders['Content-Type'] . "\n"; // image/png
echo $curl->responseHeaders['CoNTeNT-TyPE'] . "\n"; // image/png
// Manual clean up.
$curl->close();
// Example access to curl object.
curl_set_opt($curl->curl, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1');
curl_close($curl->curl);
require __DIR__ . '/vendor/autoload.php';

use Curl\MultiCurl;

// Requests in parallel with callback functions.
$multi_curl = new MultiCurl();

$multi_curl->success(function($instance) {
    echo 'call to "' . $instance->url . '" was successful.' . "\n";
    echo 'response:' . "\n";
    var_dump($instance->response);
});
$multi_curl->error(function($instance) {
    echo 'call to "' . $instance->url . '" was unsuccessful.' . "\n";
    echo 'error code: ' . $instance->errorCode . "\n";
    echo 'error message: ' . $instance->errorMessage . "\n";
});
$multi_curl->complete(function($instance) {
    echo 'call completed' . "\n";
});

$multi_curl->addGet('https://www.google.com/search', [
    'q' => 'hello world',
]);
$multi_curl->addGet('https://duckduckgo.com/', [
    'q' => 'hello world',
]);
$multi_curl->addGet('https://www.bing.com/search', [
    'q' => 'hello world',
]);

$multi_curl->start(); // Blocks until all items in the queue have been processed.

More examples are available under /examples.

Available Methods

Curl::__construct($base_url = null, $options = [])
Curl::__destruct()
Curl::__get($name)
Curl::afterSend($callback)
Curl::attemptRetry()
Curl::beforeSend($callback)
Curl::buildPostData($data)
Curl::call()
Curl::close()
Curl::complete($callback)
Curl::delete($url, $query_parameters = [], $data = [])
Curl::diagnose($return = false)
Curl::disableTimeout()
Curl::displayCurlOptionValue($option, $value = null)
Curl::download($url, $mixed_filename)
Curl::error($callback)
Curl::exec($ch = null)
Curl::execDone()
Curl::fastDownload($url, $filename, $connections = 4)
Curl::get($url, $data = [])
Curl::getAttempts()
Curl::getBeforeSendCallback()
Curl::getCompleteCallback()
Curl::getCookie($key)
Curl::getCurl()
Curl::getCurlErrorCode()
Curl::getCurlErrorMessage()
Curl::getDownloadCompleteCallback()
Curl::getDownloadFileName()
Curl::getErrorCallback()
Curl::getErrorCode()
Curl::getErrorMessage()
Curl::getFileHandle()
Curl::getHttpErrorMessage()
Curl::getHttpStatusCode()
Curl::getId()
Curl::getInfo($opt = null)
Curl::getJsonDecoder()
Curl::getOpt($option)
Curl::getOptions()
Curl::getRawResponse()
Curl::getRawResponseHeaders()
Curl::getRemainingRetries()
Curl::getRequestHeaders()
Curl::getResponse()
Curl::getResponseCookie($key)
Curl::getResponseCookies()
Curl::getResponseHeaders()
Curl::getRetries()
Curl::getRetryDecider()
Curl::getSuccessCallback()
Curl::getUrl()
Curl::getUserSetOptions()
Curl::getXmlDecoder()
Curl::head($url, $data = [])
Curl::isChildOfMultiCurl()
Curl::isCurlError()
Curl::isError()
Curl::isHttpError()
Curl::options($url, $data = [])
Curl::patch($url, $data = [])
Curl::post($url, $data = '', $follow_303_with_post = false)
Curl::progress($callback)
Curl::put($url, $data = [])
Curl::removeHeader($key)
Curl::reset()
Curl::search($url, $data = [])
Curl::setAutoReferer($auto_referer = true)
Curl::setAutoReferrer($auto_referrer = true)
Curl::setBasicAuthentication($username, $password = '')
Curl::setConnectTimeout($seconds)
Curl::setCookie($key, $value)
Curl::setCookieFile($cookie_file)
Curl::setCookieJar($cookie_jar)
Curl::setCookieString($string)
Curl::setCookies($cookies)
Curl::setDefaultDecoder($mixed = 'json')
Curl::setDefaultHeaderOut()
Curl::setDefaultJsonDecoder()
Curl::setDefaultTimeout()
Curl::setDefaultUserAgent()
Curl::setDefaultXmlDecoder()
Curl::setDigestAuthentication($username, $password = '')
Curl::setFile($file)
Curl::setFollowLocation($follow_location = true)
Curl::setForbidReuse($forbid_reuse = true)
Curl::setHeader($key, $value)
Curl::setHeaders($headers)
Curl::setInterface($interface)
Curl::setJsonDecoder($mixed)
Curl::setMaxFilesize($bytes)
Curl::setMaximumRedirects($maximum_redirects)
Curl::setOpt($option, $value)
Curl::setOpts($options)
Curl::setPort($port)
Curl::setProtocols($protocols)
Curl::setProxy($proxy, $port = null, $username = null, $password = null)
Curl::setProxyAuth($auth)
Curl::setProxyTunnel($tunnel = true)
Curl::setProxyType($type)
Curl::setRange($range)
Curl::setRedirectProtocols($redirect_protocols)
Curl::setReferer($referer)
Curl::setReferrer($referrer)
Curl::setRetry($mixed)
Curl::setStop($callback = null)
Curl::setTimeout($seconds)
Curl::setUrl($url, $mixed_data = '')
Curl::setUserAgent($user_agent)
Curl::setXmlDecoder($mixed)
Curl::stop()
Curl::success($callback)
Curl::unsetHeader($key)
Curl::unsetProxy()
Curl::verbose($on = true, $output = 'STDERR')
MultiCurl::__construct($base_url = null)
MultiCurl::__destruct()
MultiCurl::addCurl(Curl $curl)
MultiCurl::addDelete($url, $query_parameters = [], $data = [])
MultiCurl::addDownload($url, $mixed_filename)
MultiCurl::addGet($url, $data = [])
MultiCurl::addHead($url, $data = [])
MultiCurl::addOptions($url, $data = [])
MultiCurl::addPatch($url, $data = [])
MultiCurl::addPost($url, $data = '', $follow_303_with_post = false)
MultiCurl::addPut($url, $data = [])
MultiCurl::addSearch($url, $data = [])
MultiCurl::afterSend($callback)
MultiCurl::beforeSend($callback)
MultiCurl::close()
MultiCurl::complete($callback)
MultiCurl::disableTimeout()
MultiCurl::error($callback)
MultiCurl::getOpt($option)
MultiCurl::removeHeader($key)
MultiCurl::setAutoReferer($auto_referer = true)
MultiCurl::setAutoReferrer($auto_referrer = true)
MultiCurl::setBasicAuthentication($username, $password = '')
MultiCurl::setConcurrency($concurrency)
MultiCurl::setConnectTimeout($seconds)
MultiCurl::setCookie($key, $value)
MultiCurl::setCookieFile($cookie_file)
MultiCurl::setCookieJar($cookie_jar)
MultiCurl::setCookieString($string)
MultiCurl::setCookies($cookies)
MultiCurl::setDigestAuthentication($username, $password = '')
MultiCurl::setFile($file)
MultiCurl::setFollowLocation($follow_location = true)
MultiCurl::setForbidReuse($forbid_reuse = true)
MultiCurl::setHeader($key, $value)
MultiCurl::setHeaders($headers)
MultiCurl::setInterface($interface)
MultiCurl::setJsonDecoder($mixed)
MultiCurl::setMaximumRedirects($maximum_redirects)
MultiCurl::setOpt($option, $value)
MultiCurl::setOpts($options)
MultiCurl::setPort($port)
MultiCurl::setProxies($proxies)
MultiCurl::setProxy($proxy, $port = null, $username = null, $password = null)
MultiCurl::setProxyAuth($auth)
MultiCurl::setProxyTunnel($tunnel = true)
MultiCurl::setProxyType($type)
MultiCurl::setRange($range)
MultiCurl::setRateLimit($rate_limit)
MultiCurl::setReferer($referer)
MultiCurl::setReferrer($referrer)
MultiCurl::setRequestTimeAccuracy()
MultiCurl::setRetry($mixed)
MultiCurl::setTimeout($seconds)
MultiCurl::setUrl($url, $mixed_data = '')
MultiCurl::setUserAgent($user_agent)
MultiCurl::setXmlDecoder($mixed)
MultiCurl::start()
MultiCurl::stop()
MultiCurl::success($callback)
MultiCurl::unsetHeader($key)
MultiCurl::unsetProxy()
MultiCurl::verbose($on = true, $output = 'STDERR')

Security

See SECURITY for security considerations.

Troubleshooting

See TROUBLESHOOTING for help troubleshooting.

Testing

See TESTING for testing information.

Contributing

  1. Check for open issues or open a new issue to start a discussion around a bug or feature.
  2. Fork the repository on GitHub to start making your changes.
  3. Write one or more tests for the new feature or that expose the bug.
  4. Make code changes to implement the feature or fix the bug.
  5. Send a pull request to get your changes merged and published.

php-curl-class's People

Contributors

3kbest avatar amranich avatar blaaat avatar case avatar dependabot[bot] avatar failpunk avatar giansalex avatar github-actions[bot] avatar gormartsen avatar isecret avatar maxvodo avatar mydansun avatar oxicode avatar petewatts avatar pezmc avatar philipp91 avatar robinvandervliet avatar rockerboo avatar sebwas avatar sganz avatar thebeline avatar tixlegeek avatar user52 avatar volch avatar willianpts avatar woxcab avatar yahasana avatar zachborboa avatar zborboa-g avatar zuorambo 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  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

php-curl-class's Issues

Add example for gzipped/compressed content

Some users may benefit from being show the exmple for compressed content option:

setHeader('Accept-Encoding', 'gzip,deflate'); $curl->setOpt(CURLOPT_ENCODING , ""); $curl->setOpt(CURLOPT_RETURNTRANSFER, 1); ?>

Namespace and Composer wanted! :D

Hi again, mate!

Have you thought about putting a Namespace to your CurlClass. It would be nice to integrate with frameworks like Symfony2 (which I use in many projects) and a Namespace and Composer config file makes it much easier to integrate :)

Thanks for your time, and for your working code!
Dani.

Nested arrays in data array are encoded at the same level as it's father array

If we have our data like this:

$curl = new Curl();
$curl->post('http://www.example.com/login/', array(
    'username' => 'myusername',
    'password' => 'mypassword',
    'more_data' => array(
        'param1' => 'something',
        'param2' => 'other thing',
        'another' => array(
            'extra' => 'level',
            'because' => 'I need it'
        )
    )
));

the http_build_multi_query function causes the another array to lose its nested index from more_data['another'] => array() to another => array(). So we would get something like:

array(
    username' => 'myusername',
    'password' => 'mypassword',
    'more_data' => array(
        'param1' => 'something',
        'param2' => 'other thing'
    ),
    'another' => array(
        'extra' => 'level',
        'because' => 'I need it'
    )
)

It also affects to the hypothetical sublevels of the another => array() and it's sublevels, and more, and more...

I'm preparing a pull request to solve this problem.

Add setUrl() method

Typically when working with APIs, all requests are sent to the same URL. It doesn't make sense to specify this over and over again. There should be a single call to set the URL to use for every request.

Curl Class line 135 suggestion

I'd recommend doing something like this, since passing by reference is being ousted

private function _postfields($data) {
    if (is_array($data)) {
        if (is_array_multidim($data)) {
            $data = $this->http_build_multi_query($data);
        }
        else {
            $trim = array();
            foreach ($arr AS $name => $part) $trim[$name] = array_filter($part); // empty
            $data = $trim;
        }
    }
    return $data;
}

Integer params inside data array aren't taken in account

If we have our data like this:

$curl = new Curl();
$curl->post('http://www.example.com/login/', array(
  'username' => 'myusername',
  'password' => 'mypassword',
  'number' => 1234

);

The http_build_multi_query function causes the number param to lose because the numbers aren't added, only strings. So we would get something like:

$curl = new Curl();
$curl->post('http://www.example.com/login/', array(
  'username' => 'myusername',
  'password' => 'mypassword'

);

I'm preparing a pull request to solve this problem, at least to allow Integer types to be added.

Add PHP 5.3 to tests

Add PHP 5.3 to tests for syntax checking, but exclude it from the phpunit tests as the built-in development server is only available >= 5.4.0.

language: php
php:
  - 5.3
script:
  - php -l src/Curl.class.php
  - if [[ "$TRAVIS_PHP_VERSION" != "5.3" ]]; then
      cd tests && phpunit --configuration phpunit.xml
    fi

response_headers return only one cookies since updated to latest version

Request Headers

  • :host:www.google.com.tw
  • :method:GET
  • :path:/
  • :scheme:https
  • :version:HTTP/1.1
  • accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,/;q=0.8
  • accept-encoding:gzip,deflate,sdch
  • accept-language:zh-TW,zh;q=0.8,en-US;q=0.6,en;q=0.4,zh-CN;q=0.2
  • cache-control:max-age=0
  • dnt:1
  • user-agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.154 Safari/537.36
CaseInsensitiveArray Object
(
    [container:CaseInsensitiveArray:private] => Array
        (
            [Request-Line] => GET / HTTP/1.1
            [User-Agent] => Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1
            [Host] => www.google.com.tw
            [Accept] => */*
        )
)

Response Headers

  • alternate-protocol:443:quic
  • cache-control:private, max-age=0
  • content-encoding:gzip
  • content-type:text/html; charset=UTF-8
  • date:Sat, 29 Mar 2014 08:24:42 GMT
  • expires:-1
  • p3p:CP="This is not a P3P policy! See http://www.google.com/support/accounts/bin/answer.py?hl=en&answer=151657 for more info."
  • server:gws
  • set-cookie:PREF=ID=22ca221b979ef9a5:FF=0:TM=1396081482:LM=1396081482:S=LDXIcjyPh8Vo4Zjy; expires=Mon, 28-Mar-2016 08:24:42 GMT; path=/; domain=.google.com.tw
  • set-cookie:NID=67=HpzSxC9nIT7YVrCK67WutR2TVGT6YemKzqajSn_diBhqUi-ucSoIez6krWWOArXS3D_gYsFyLIfXKNMXMkhVkrbXqENyu4HCKTrKB4r69kYufOtL53aiZRDPt-2z5p6x; expires=Sun, 28-Sep-2014 08:24:42 GMT; path=/; domain=.google.com.tw; HttpOnly
  • status:200 OK
  • version:HTTP/1.1
  • x-frame-options:SAMEORIGIN
  • x-xss-protection:1; mode=block
CaseInsensitiveArray Object
(
    [container:CaseInsensitiveArray:private] => Array
        (
            [Status-Line] => HTTP/1.1 200 OK
            [Date] => Sat, 29 Mar 2014 08:22:52 GMT
            [Expires] => -1
            [Cache-Control] => private, max-age=0
            [Content-Type] => text/html; charset=UTF-8
            [Set-Cookie] => NID=67=CRO8x-Iq2rxcEG1ajYd1-dgOMuOxVrXu0sE1Hp13scFOtbfKNNM9w1p_bh5QqBZI7gZ_Qz_r6Gc8m2VLhDv8WOiWrER5ozJwMK55ZLC1fHsq2-3kskPrD-uP0Q6RPs35; expires=Sun, 28-Sep-2014 08:22:52 GMT; path=/; domain=.google.com.tw; HttpOnly
            [P3P] => CP="This is not a P3P policy! See http://www.google.com/support/accounts/bin/answer.py?hl=en&answer=151657 for more info."
            [Server] => gws
            [X-XSS-Protection] => 1; mode=block
            [X-Frame-Options] => SAMEORIGIN
            [Alternate-Protocol] => 443:quic
            [Transfer-Encoding] => chunked
        )

)

auto json_decode as array?

Is it possible to implement any option to get answer from json as array?
Or option for turning off auto json_decode().

Tag a Release

Would you consider tagging a release for this repo to allow easy integration with Composer? I forked the repo and tagged it as 0.5.0.

Arrays inside the data array loses its indexes

If we have our data like this:

$curl = new Curl();
$curl->post('http://www.example.com/login/', array(
    'username' => 'myusername',
    'password' => 'mypassword',
    'more_data' => array(
        'param1' => 'something',
        'param2' => 'other thing',
        'param3' => 123
));

the http_build_multi_query function causes the more_data array to lose its indexes. So we would get something like:

array(
    [username] => 'myusername',
    [password] => 'mypassword',
    [more_data] => array(
        [0] => 'something',
        [1] => 'other thing',
        [2] => 123
)

I'm preparing a pull request to solve this problem.

Return response body when calling get(), post(), etc.

Look into returning the response body when calling http methods get(), post(), etc.

This will allow:

$curl = new Curl();
foreach ($curl->get($url) as $key => $value) {
    echo $key . ' ' . $value . "\n";
}

even

foreach ((new Curl())->get($url) as $key => $value) {
    echo $key . ' ' . $value . "\n";
}

instead of all this

$url = 'https://www.example.com/api/user.json';
$curl = new Curl();
$curl->get($url);
foreach ($curl->response as $key => $value) {
    echo $key . ' ' . $value . "\n";
}

Next tagged release?

Hello,

Many new features are in the dev-master branch. I was curious when the next tagged release will be. Thanks for your time.

how to remove header server information but tag head not remove

I was try to get content of 1 site , but when I use normal method will be print the info of header server.
header

then i try to disable header the head sections is gone , or some content is gone...!
how to disable print get_info of the curl header?
and just opinion , by default on exec, the request header is not activate , and gave the new function for get or activate header.
thank you :)

Add hhvm to tests

Add hhvm to tests.

language: php
php:
  - hhvm
matrix:
  allow_failures:
    - php: hhvm

Curl CLose is not a Valid CURL Handle

I was try with the example of the git,
everythings is okay, but when I try to close the cURL , Always get the errors.

Warning: curl_close(): 4 is not a valid cURL handle resource in Curl.class.php on line 158

I try this simple code

<?php
require_once 'Curl.class.php';
$l = 'abcdef';
$b= 'defgh';

$curl = new Curl();
$curl->setUserAgent('');
$curl->setReferrer('');
$curl->post('http://localhost/testlink.php', array(
            'l' => $l,
            'b' => $b,
));
if ($curl->error) {
    echo $curl->error_code;
}
else {
    print_r($curl->response);
}
$curl->close(); // this will be thrown error, though I try to close with curl_close($curl->curl)

any help?

Include PHP_VERSION and curl version in user-agent

$user_agent = 'PHP-Curl-Class/' . Curl::VERSION . ' (+https://github.com/php-curl-class/php-curl-class)';
$user_agent .= ' PHP/' . PHP_VERSION;

$curl_version = curl_version();
$user_agent .= ' curl/' . $curl_version['version'];

Allow access to raw response content

Set $curl->raw_response to allow for access to raw response content.

$curl = new Curl();
$curl->get('http://www.example.com/data.json');
$curl->response = json_decode($curl->raw_response, true);

#63

Requested url contains trailing "?"

The get, put, and delete methods include a trailing question mark when making the corresponding http request is called. The request should not call the url with a trailing ? unless it is explicitly specified in the url.

$this->setopt(CURLOPT_URL, $url . '?' . http_build_query($data));

Add docs

Add documentation

ref: 14607715c6a1e161

Add $curl->unsetHeader()

public function unsetHeader($key)
{
    $this->headers[$key] = $key . ':';
    $this->setOpt(CURLOPT_HTTPHEADER, array_values($this->headers));
    unset($this->headers[$key]);
}

Use PSR coding standards

Use PSR coding standards for all php code including examples/*.php and tests/PHPCurlClass/*.php. Include these in tests/syntax.sh.

Change assertTrue to assertEquals

Change instances of

PHPUnit_Framework_Assert::assertTrue('foo' === 'foo');

to

PHPUnit_Framework_Assert::assertEquals('foo', 'foo');

PATCH problem

Hi.
When i am making request PATCH i getting in response body params (yii2):

------------------------------60716153b45c
Content-Disposition:_form-data;_name' => string '"surname"

loele
------------------------------60716153b45c--

My query code:

$curl->setHeader('Authorization', 'Bearer '.$apiKey);
$curl->setHeader('Content-Type' , 'application/x-www-form-urlencoded');
$curl->setHeader('Accept' , 'application/json; version=v1.0');

$curl->patch('api.host.dev',[ 'surname' => string 'loele']);

When i am requesting server with the same data but using PUT it works perfect.
What am i doing wrong?

Regards

PS.Using Fiddler query comopser PATCH work great. But there is added automatically Content-Length header.

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.