...
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
// Returns the server name. Example: Apache/2.4.29 (Ubuntu) $serverName = $wrapper->getHeader('Server'); // Returns full HTTP header response with code. Example: 200 OK $httpHeadResponse = $wrapper->getHeader('HTTP'); // Returns the HTTP header response code only. Example: 200 $httpCode = $wrapper->getCode(); |
Basic Requests
The most basic request is done with simply using request(). The only argument it actually needs is the URL, and then you can start using the above get-methods to retrieve what you need from the site. There are however a bunch of arguments to use here, including multi-requests (i.e. for curl and the wrappers that supports multiple requests in the same call).
require()-argument | Format | Description |
---|---|---|
url | string or array | The only one you need. |
data | array | Data to include in the request as an array. Formatted as default postdata if nothing else is given. |
method | RequestMethod:: | RequestMethod is GET, POST, PUT, DELETE, HEAD, REQUEST, PATCH |
dataType | DataType:: | How data is posted in the request. Can be NORMAL (?var=val&var1=val1), JSON, SOAP, XML, SOAP_XML, RSS_XML |
String or array?
As you can see, you can add urls in the format of an array. By doing this you do an important one step up, which transform netcurl very much in a multirequest tool. Referring to the different wrappers it can look like anything from:
Code Block | ||||
---|---|---|---|---|
| ||||
(new NetWrapper())->request(
[
'http://ipv4.netcurl.org/http.php?code=200&message=Funktionsduglig',
'http://ipv4.netcurl.org/http.php?code=500&message=Kass',
'http://ipv4.netcurl.org/http.php?code=201&message=Mittemellan',
]
); |
Where the multirequet is very simple built. Or if you want to advance into something more complex:
Code Block | ||||
---|---|---|---|---|
| ||||
$wrapperFirst = (new CurlWrapper())->request([
[
'url' => 'https://ipv4.netcurl.org/',
'requestMethod' => RequestMethod::POST,
'dataType' => DataType::NORMAL,
'data' => [
'dataRequestMethod' => 'FIRST',
],
'headers' => [
'XHeaderFirst' => 'yes',
'X-Real-IP' => '255.255.255.0',
'Client-IP' => '127.0.0.255',
'X-Forwarded-For' => '127.255.0.0',
],
'headers_static' => [
'HeaderIsForever' => 'only-in-non-multi-curls',
],
],
[
'url' => 'https://ipv4.netcurl.org/',
'requestMethod' => RequestMethod::POST,
'dataType' => DataType::NORMAL,
'data' => [
'dataRequestMethod' => 'SECOND',
],
'headers' => [
'XHeaderSecond' => 'yes',
],
],
[
'url' => 'https://ipv4.netcurl.org/',
'requestMethod' => RequestMethod::GET,
'data' => [
'dataRequestMethod' => 'THIRD',
],
],
]); |
Each time the wrappers get this kind of request it always checks if curl_multi is available before using the simpler methods. So you can use this urllist as a simple array, or associative array.
This is some of the arguments in a associative array.
Argument | Description |
---|---|
url | See above |
requestMethod | See above |
dataType | See above |
data | See above |
headers | Extra headers to include into the request. |
headers_static | Extra headers to include into the request, but they will restored even if the wrapper is reset between the requests. |