Get pages from site, manage the cookies between the pages, allow to follow the redirects. The cookies can be stored in an external file compatible with Netscape's cookies.txt. It allow to send forms fields or files.
$httpclient = new Domframework\Httpclient ();
$httpclient->useragent ("Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0")
$content = $httpclient->getPage ("http://www.example.com");
$httpclient = new Domframework\Httpclient ();
$httpclient->headerAdd ("Content-Type", "application/json")
->url ("http://www.example.com")
->method ("POST");
$httpclient->connect ();
$page3 = $httpclient->getContent ();
$page6 = $httpclient->method ("POST")
->formData (['taskId' => 'aUniversMesComptes'])
->url ($url)
->connect ()
->getContent ();
Namespace Domframework
/** This programe allow to get a HTTP page from a site, and examine the content. It will store the Cookies, allow to do the redirects, follow links and get form / input and send the values.
No property available
/** The constructor
/**
Get/Set the accept type of page wanted by the client
@param string|null $accept
The accept types with weight
/**
Get/Set the accept Encoding wanted by the client
@param string|null $acceptEncoding
The encoding requested
/**
Get/Set the accept Language wanted by the client
@param string|null $acceptLanguage
The languages with weight
/** Set the authentication in Basic type@param string $login
The login to use@param string $password
The password to use
/** Get/Set authentication To remove authentication, pass "" to $auth arg@param string|null $auth
The authentication string to send@return
value or $this
/**
Return the base URL of the site
@return
the URL
/** Init the connection to URL Will fill the headersReceived, cookies and port properties.@param array|null $ssloptions
The SSL options (stream_context_set_option)@return
$this
/** Add a cookie in the store If the cookie already exists, the old one is replaced by the new value@param string $domain
The domain to use@param string $cookie
The cookie content to store
/** Check if some stored cookies must be send to the server, because they are in the same domain.@param string $url
The URL requested@return
array the cookies to add to the headers send to the server
/**
Set / Get the cookies stored
@param array|null $cookies
Set / Get the cookies
/**
Get / Set the Store of session cookies when analyzing the answer of the
server
@param boolean|null $cookiesSession
Allow to store the session cookies
/**
Set / Get the debug mode
0: Nothing is displayed, 1: Only URL are displayed,
2: headers only send and received, 3: all the content, but without sent
files, 4: all the content
@param boolean|null $debug
The debug value to set or get
/** Disconnect the connection
/**
Set / Get the form Data
Will be of type array ("field" => "value")
If value is like "@/tmp/file", use the /tmp/file as content
@param array|null $formData
The data to send to the server
/** Get the content from the server and put it in memory
/** Return the TCP infos of the connection
/** Get meta data, like the timeout state, the crypto protocol and ciphers...
/** Get the page Will fill the headersReceived, cookies and port properties. This will fill all the RAM if the page is too big. For big files, use $httpclient->url ($url) ->connect () ; while ($content = $httpclient->read ()) {} $httpclient->disconnect (); If no maxsize limit is set, limit the download to 8G@param string $url
The URL to get@param array|null $ssloptions
The SSL options (stream_context_set_option)@return
the page body
/** Add a new header to be sent to the server@param string $header
The header to add/update@param string $value
The value to save
/** Get the headersReceived after the page was get
/** Set the headers to initial value
/** Get the headers sent to the server after the page was get
/** Get the HTTP Return code from connection
/** Display the log message@param integer $priority
The minimal priority to display the message@param mixed $message
The message to display
/**
Set / Get the maximum maxsize allowed
@param integer|null $maxsize
The maxsize in bytes
/**
Set / Get the method
@param string|null $method
Set / Get the method
/** Get the port used for connection
/**
Set / Get the content Data
The data is in raw format and will not be modified.
Overwrite the eventually previous form data and rawData
@param string|null $rawData
The data to use
/**
Read max MAXSIZE bytes
Return "" if all the file is received
3 methods are supported : Chunked mode, Content-Length defined and all
until the connection will be closed by the server
@param integer $maxsize
The maxsize to get in this read
/**
Get / Set the actual number of redirect
@param integer|null $redirectCount
The actual number of redirect
/**
Get / Set the maximum number of redirect to follow before aborting
@param integer|null $redirectMaxCount
The maximum number of redirect
before exception
/**
Get/Set the referer page
@param string|null $referer
The new referer that will be used on next
request
/** Get/Set the ssl options@param array|null $ssloptions
The SSL Options to use@return
$this
/**
Get / Set the timeout in second before expiring the connection
30s by default
@param integer|null $timeout
The timeout value
/**
Set / Get the url
@param string|null $url
Set / Get the url
/**
Get / Set the useragent sent to the server. If it is empty, it will not be
sent
@param string|null $useragent
The user agent to use