Git Product home page Git Product logo

curl-http-client's Introduction

curl-http-client

Travis CI Status

CurlHttpClient is a object oriented wrapper of PHP cURL extension. It includes a class CurlHttpClient and a set of handy apis, which are a set of static methods included in the class. Besides, a Yii framework component wrapper is provided with it.

API List

Static functions

  1. CurlHttpClient::getInstance()
  2. CurlHttpClient::get()
  3. CurlHttpClient::getJson()
  4. CurlHttpClient::post()
  5. CurlHttpClient::postJson()

Properties

  1. $version

Methods

  1. __construct()
  2. reset()
  3. getRequest()
  4. postRequest()
  5. setCookie()
  6. setCookies()
  7. setHeader()
  8. setHeaders()
  9. setQuery()
  10. setQueries()
  11. setCurlOption()
  12. getErrorCode()
  13. getErrorMsg()
  14. getRawResponseHeader()
  15. getResponseHeaders()
  16. getResponseBody()

Documents

CurlHttpClient::getInstance()

Description

A singleton factory to generate a single CurlHttpClient object.

Parameters

void

Return value

This function will return a CurlHttpClient object when success, or false on failure.

CurlHttpClient::get()

Description

Simple and handy GET request

Parameters

  • $url --- request url
  • $queries --- request parameters
  • $cookies --- cookies from last request
  • $headers --- headers should include

Return value

The request result will be returned in a string.

CurlHttpClient::getJson()

Description

Simple and handy GET request, but the result is JSON

Parameters

  • $url --- request url
  • $queries --- request parameters
  • $cookies --- cookies from last request
  • $headers --- headers should include

Return value

The request result will be treated as JSON string and before returned, the json_decode function will be called.

CurlHttpClient::post()

Description

Simple and handy POST request

Parameters

  • $url --- request url
  • $queries --- request parameters
  • $cookies --- cookies from last request
  • $headers --- headers should include

Return value

The result string of the POST request.

CurlHttpClient::postJson()

Description

Simple and handy POST request, but the result is JSON

Parameters

  • $url --- request url
  • $queries --- request parameters
  • $cookies --- cookies from last request
  • $headers --- headers should include

Return value

The request result will be treated as JSON string and before returned, the json_decode function will be called.

$version

This static variable is set to the version of the class.

__construct()

The constructor of the CurlHttpClient object.

Parameters

void

Return value

void

reset()

This method will reset the cURL resource and clear the last request information.

Parameters

void

Return value

void

getRequest()

Send the request with HTTP GET method.

Parameters

  • $url

Return value

The response body of the requst.

postRequest()

Send the request with HTTP POST method.

Parameters

  • $url

Return value

The response body of the requst.

setCookie()

Set the request cookie.

Parameters

  • $key string
  • $value string

Return value

void

setCookies()

Set the request cookies by array or cookie string.

Parameters

  • $cookies mixed this argument could be a string like(key1=val1; key2=val2) or a associative array of PHP.

Return value

void

setHeader()

Set the request header with key and value.

Parameters

  • $key string
  • $value string

Return value

void

setHeaders()

Set headers with associative array.

Parameters

  • $headers array

Return value

void

setQuery()

Set the quest parameter.

Parameters

  • $key string
  • $value string

Return value

void

setQueries()

Set multiple query parameters with query string or associative array.

Parameters

  • $queries mixed string/array

Return value

setCurlOption()

Set the cURL option to the cURL resource handler in the object.

Parameters

  • $option int this should be the cURL predefined constant.
  • $value mixed

Return value

void

getErrorCode()

Get the error code the cURL returned after the request.

Parameters

void

Return value

The error code of the cURL.

getErrorMsg()

Get the string error message information of cURL.

Parameters

void

Return value

The error message cURL generated.

getRawResponseHeader()

Get the response header of the request. This is in raw, that means a single string, each response header in the string is separated by "\r\n"

Parameters

void

Return value

The response header of the request.

getResponseHeaders()

Get the header string parsed result. The header string will be parse to an associative array, the header name will be the key and the header value will be the value.

Parameters

void

Return value

array

getResponseBody()

Parameters

void

Return value

string

curl-http-client's People

Contributors

charlestang avatar

Stargazers

 avatar

Forkers

anzeljg

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.