PHP code example of casivaagustin / phrequests

1. Go to this page and download the library: Download casivaagustin/phrequests library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

casivaagustin / phrequests example snippets

 php
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
  curl_setopt($ch, CURLOPT_MAXREDIRS, 3);
  curl_setopt($ch, CURLOPT_URL, 'http://www.google.com');

  $result = curl_exec($ch);

  if (curl_errno($ch) > 0) {
    //Handle Error
  }

  curl_close($ch);
 php
$response = \PHRequests\PHRequests::get('http://www.google.com');
 php
$opt = array (
  'param1' => 'Some Value',
  'param2' => 'Some other value',
);

$response = \PHRequests\PHRequests::post('http://www.httpbin.org/post', $opt);
 php
$options = array(
 'proxy' => array(
    'url' => 'http://prx_name_or_ip:3128'         
  ),
);
$response = \PHRequests\PHRequests::options(BASE_GET_URL, $options);
 php
$options = array(
 'proxy' => array(
    'url' => 'http://prx_name_or_ip:3128',
    'auth' => 'username:password',
    'auth_method' => Auth::BASIC //Optional, BASIC By default, NTLM is the second option. 
  ),
);

$response = \PHRequests\PHRequests::options(BASE_GET_URL, $options);
 php
$options = array (
  'ssl_ca' => '../certs/mycert.pem';
)
$response = PHRequests::get('https://www.mysite.com', $options);
 php
\PHRequests\PHRequests::saveRemoteFile($urlSource, $pathDest, $options);