Code Monkey home page Code Monkey logo

php-http-request's Introduction

php-http-request

php http request for curl

Http request

COMMON OPTION

  • Http/request::addOpts($key,$val = null);

    add curl opts

  • Http/request::setOpts($key,$val = null);

    set a curl opts

  • Http/request::setTimeout($timeMS);

    set curl timeout ms

  • Http/request::setConnectTimeout($timeMS);

    set curl connect timeout ms

  • Http/request::setVerify($Peer = true,$Host = true);

    set ssh config verifyPeer and verifyHost

  • Http/request::setCookie($cookie);

    set cookie jar with string

  • Http/request::cookieFile($cookieFile);

    set cookie jar with cookie file

  • Http/request::auth($username = '', $password = '', $method = CURLAUTH_BASIC);

    set auth (basic)

  • Http/request::proxy($address, $port = 1080, $type = CURLPROXY_HTTP, $tunnel = false);

    set proxy for client

  • Http/request::proxyAuth($username = '', $password = '', $method = CURLAUTH_BASIC);

    set proxy auth for client

GET METHOD

$response = Http/request::get($url, $headers = array(),$params=null,$parameters = null, $username = null, $password = null);

POST METHOD

$response = Http/request::post($url, $headers = array(),$body=null,$parameters = null, $username = null, $password = null);

PUT METHOD

$response = Http/request::put($url, $headers = array(),$body=null,$parameters = null, $username = null, $password = null);

PATCH METHOD

$response = Http/request::patch($url, $headers = array(),$body=null,$parameters = null, $username = null, $password = null);

DELETE METHOD

$response = Http/request::delete($url, $headers = array(), $params = null, $username = null, $password = null)

OPTIOMS METHOD

$response = Http/request::options($url,$header=[],$params=null,$parameters = null, $username = null, $password = null);

CONNECT METHOD

$response = Http/request::connect($url,$header=[],$params=null,$parameters = null, $username = null, $password = null);

TRACE METHOD

$response = Http/request::trace($url,$header=[],$params=null,$parameters = null, $username = null, $password = null);

Upload Field

  • Http/request::File($filename, $mimetype = '', $postname = '');

Prepares a file for upload. To be used inside the parameters declaration for a request

 @param string $filename The file path
 @param string $mimetype MIME type
 @param string $postname the file name
 @return string|\CURLFile

Multipart Field

  • Http/request::Multipart($data, $files = false);

Http Response

  • $response->status();

get response http status (int)

  • $response->body();

get response http body

  • $response->data();

get response http body with json_decode

Error Code

if stauts <= 0 then body return a error msg and stauts means curl error code

DEMO

<?php
include "request.php"
Http/request::setTimeout(1500);
$resp = Http/request::get("https://www.baidu.com");
echo $resp->status();
echo "\r\n";
echo $resp->body();

php-http-request's People

Contributors

mlboy avatar

Watchers

 avatar

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.