Jump to the project tracker to join this project - or report bugs!
The network- and cURL class is an independent class library that handles network related things. The cURL library especially, has special features, like parsing data received from the body. For example, calling an URL that returns json strings, you'll get an object back that you could handle immediately, instead of parsing the data yourself.
We are with the cURL class in a quite verbose mode, to get the most out of the web request you are doing. The response are separated in an array as follows
array key | array content value | ||
---|---|---|---|
code | The current HTTP Status code returned from the request (See https://en.wikipedia.org/wiki/List_of_HTTP_status_codes) This response status code can be used to detect, for example 404 not found errors, or similar, of a page. By means, you may throw optional exceptions by checking this code state as you need. | ||
header | The full response header returned from the request as ...
... where info is an array with keys and values. Example:
| ||
body | The full returned body of the request | ||
parsed | If the body are recognized as specially formatted (json, xml, etc), the parsed array will transform into an object or an array, depending on the content. Currently, the parser supports simpler modes like XML (SimpleXMLElement) and by this also RSS-feeds (unconfirmed), JSON and serialized data. |
As of the release of 20161213 (which can be found in the repo), all functions that allows postData to be sent in a web call may be posted quite freely. You can either put postData in the standard format like:
¶m1=value1¶m2=value2
You may also sent your requested data through the function as an array() or even a JSON-object. Such call may look like this:
doPost("http://test.com/", $postDataObject, CURL_POST_AS::POST_AS_JSON) |
The function itself tries to detect if the input $postDataObject is encoded or decoded (keep in mind that problems with NAN-values or similar is not supported).
There are four basic function calls, that by default handles http calls automatically. Normally, no further settings are required except for calling an URL. Posting data could be made manually or as an object. It also handles proxies, outgoing ip-addresses and hopefully also the ability to switch to explicit ipv6- or ipv4-mode.
A very basic call to the library may look like this. By using the "parsed" key in the response, you'll get any supported output formatted correctly.
require_once("tornevall_network.php"); $CURL = new \TorneLIB\Tornevall_cURL(); $getResponse = $CURL->doGet("https://api.tornevall.net/2.0/endpoints/getEndPoints"); print_r($getResponse['parsed']); |
For the moment the library supports following formats:
Note: SOAP is using our class Tornevall_SimpleSoap to handle soap-calls - by adding ?wsdl, &wsdl (depending on how the post/get-parameters looks) or setting CURL_POST_AS to POST_AS_SOAP, the SOAP handler will be activated - or not.
require_once("tornevall_network.php"); $CURL = new \TorneLIB\Tornevall_cURL(); $Response = $CURL->doGet("https://test.com/wsdlService?wsdl"); echo "<pre>"; try { $getResponse = $Response->getOneResponseHere(); print_R($getResponse['parsed']); } catch (Exception $e) { echo "Exception Thrown: " . $e->getMessage() . "\n"; $getResponse = $Response->getLibResponse(); } echo "</pre>"; |