Download the PHP package rsong/phprequest without Composer
On this page you can find all versions of the php package rsong/phprequest. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package phprequest
Statement
It's a copy of https://github.com/ptcong/easyrequest
EasyRequest
A light weight PHP http client implements PSR7, use socket/curl for sending requests.
Features
- All general features as other libraries
- Upload large file (larger than 2GB)
- Supports HTTP proxy, SOCKS4, SOCKS4A, SOCKS5 (both CURL and Socket handler).
- Use PSR-7 http messages
Requirements
- Socket enabled or curl extension installed
- PHP 5.3+
Installation
Sometimes you don't want to use composer, just want to include only one file as way our old library does (ptcong/php-http-client). Let run build/run.php
script to get compiled.php
file and include it at the top of your script.
Usage
- Create a client
- Set request options
- Quick request
- Add headers to request
- Working with cookies (set, get)
- Add query string
- Add form params (post form)
- Add multipart data
- Upload file
- Post raw data
- Post JSON data
- Working with SOCKS, PROXY
- Auth basic
- Bind request to specific IP
- Get response
- Get all redirected requests
- Get debug, error message
Create a request
Client::request
method just create a new instance of \EasyRequest\Client
class.
with default options
Set request options
withOption
method will overide to existing option. If you want to append query string, form params to current option, read it under.
Quick request
This methods will create new request and send immediately, you don't need to call send()
method here.
Add header to request
Working with cookies
You can use header
option to add cookie as above, but we already have CookieJar
to handle cookie for you.
By deaults, Client class will automatic create an CookieJar
instance before sending request if cookie_jar is not set.
You can choose:
FileCookieJar
to write cookies to file as browser, next request it will use cookies from this file.SessionCookieJar
to write cookies to $_SESSION (remember, you have added session_start() at the top of your script)CookieJar
just write cookies to array and all cookies will be lost if your script run completed.
Get response cookies
You can use $jar->getFor($domain, $path)
method to get cookies for specific domain and path.
This method will create new CookieJar instance contains your cookies
Add query string
or you can use withQuery
method, it's dynamic method and can handle some cases
Add form params
This is similar with Add query string
and you can use withFormParam
method same as withQuery
Add multipart data
Each multipart part requires name
, contents
Upload file
You can use multipart option to upload file, but use this method is more easier.
Post RAW data
Post JSON data
Used to easily upload JSON encoded data as the body of a request. A Content-Type: application/json
header will be added if no Content-Type header is already present on the message.
Working with proxy
You may use a HTTP or SOCKS4, SOCKS4A, SOCKS5 Proxy.
Auth basic
Bind request to interface
Get Response
When working with follow redirects option, sometimes you may want to get current url (last redirected url).
This getCurrentUri
method will returns \Psr\Http\Message\UriInterface
Get redirected requests
When use follow_redirects option, sometimes you want to get all the requests and responses.
Each request and response are following PSR7
Get responses
Get debug info
When a request is fail, you can use $request->getError()
to see error message.
and use $request->getDebug()
to see some debug information.