Some examples of using class HTTP


PHP: class HTTP – A Curl Alternative – support proxy, socks4, socks4a, socks5, ssh …

Example 1: HTTP request

<?php

require "../http.php";

$http = new http;

$response = $http->get('http://httpbin.org/get?website=tutorialspots.com');

var_dump($response);

$response = $http->get('http://httpbin.org/get?website=tutorialspots.com',2);

var_dump($response);

$response = $http->get('http://httpbin.org/get?website=tutorialspots.com',3);

var_dump($response);

$response = $http->get('http://httpbin.org/get?website=tutorialspots.com',4);

var_dump($response);

Result:

string(409) "{
  "args": {
    "website": "tutorialspots.com"
  }, 
  "headers": {
    "Content-Type": "application/x-www-form-urlencoded", 
    "Host": "httpbin.org", 
    "User-Agent": "Mozilla/5.0 (Windows NT 6.1; rv:8.0.1) Gecko/20100101 Firefox/8.0.1", 
    "X-Amzn-Trace-Id": "Root=1-5ebe30d5-3d0edbec2aa87554ba2546f2"
  }, 
  "origin": "21.66.203.234", 
  "url": "http://httpbin.org/get?website=tutorialspots.com"
}"
array(8) {
  [0]=>
  string(15) "HTTP/1.1 200 OK"
  [1]=>
  string(35) "Date: Fri, 15 May 2020 06:04:06 GMT"
  [2]=>
  string(30) "Content-Type: application/json"
  [3]=>
  string(19) "Content-Length: 478"
  [4]=>
  string(17) "Connection: close"
  [5]=>
  string(23) "Server: gunicorn/19.9.0"
  [6]=>
  string(30) "Access-Control-Allow-Origin: *"
  [7]=>
  string(38) "Access-Control-Allow-Credentials: true"
}
array(7) {
  ["Date"]=>
  string(29) "Fri, 15 May 2020 06:04:06 GMT"
  ["Content-Type"]=>
  string(16) "application/json"
  ["Content-Length"]=>
  string(3) "478"
  ["Connection"]=>
  string(5) "close"
  ["Server"]=>
  string(15) "gunicorn/19.9.0"
  ["Access-Control-Allow-Origin"]=>
  string(1) "*"
  ["Access-Control-Allow-Credentials"]=>
  string(4) "true"
}
string(703) "HTTP/1.1 200 OK
Date: Fri, 15 May 2020 06:04:07 GMT
Content-Type: application/json
Content-Length: 478
Connection: close
Server: gunicorn/19.9.0
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true

{
  "args": {
    "website": "tutorialspots.com"
  }, 
  "headers": {
    "Content-Type": "application/x-www-form-urlencoded", 
    "Host": "httpbin.org", 
    "Referer": "http://httpbin.org/get?website=tutorialspots.com", 
    "User-Agent": "Mozilla/5.0 (Windows NT 6.1; rv:8.0.1) Gecko/20100101 Firefox/8.0.1", 
    "X-Amzn-Trace-Id": "Root=1-5ebe30d7-52c9a8907c1766e4dda286b0"
  }, 
  "origin": "21.66.203.234", 
  "url": "http://httpbin.org/get?website=tutorialspots.com"
}
"

Example 2: https request:

<?php

require "../http.php";

$http = new http;

$response = $http->get('https://httpbin.org/get?website=tutorialspots.com');

var_dump($response);

Result:

string(410) "{
  "args": {
    "website": "tutorialspots.com"
  }, 
  "headers": {
    "Content-Type": "application/x-www-form-urlencoded", 
    "Host": "httpbin.org", 
    "User-Agent": "Mozilla/5.0 (Windows NT 6.1; rv:8.0.1) Gecko/20100101 Firefox/8.0.1", 
    "X-Amzn-Trace-Id": "Root=1-5ebe344d-db377b224db1d2c0ef87ce78"
  }, 
  "origin": "21.66.203.234", 
  "url": "https://httpbin.org/get?website=tutorialspots.com"
}"

Example 3: HTTPS proxy

<?php

require "../http.php";

$http = new http;
$http->proxy('3.249.236.176:3128','','http');
$http->timeout = 160;
$response = $http->get('https://httpbin.org/get?website=tutorialspots.com',4);
 
var_dump($response);

Result:

bool(true)
string(638) "
HTTP/1.1 200 OK
Date: Fri, 15 May 2020 08:31:48 GMT
Content-Type: application/json
Content-Length: 411
Connection: close
Server: gunicorn/19.9.0
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true

{
  "args": {
    "website": "tutorialspots.com"
  }, 
  "headers": {
    "Content-Type": "application/x-www-form-urlencoded", 
    "Host": "httpbin.org", 
    "User-Agent": "Mozilla/5.0 (Windows NT 6.1; rv:8.0.1) Gecko/20100101 Firefox/8.0.1", 
    "X-Amzn-Trace-Id": "Root=1-5ebe5374-6d4935e21088a2febf74c025"
  }, 
  "origin": "3.249.236.176", 
  "url": "https://httpbin.org/get?website=tutorialspots.com"
}
"

Example 4: SOCKS5

<?php

require "../http.php";

$http = new http;
$http->proxy('127.0.0.1:3003','','socks5');
$http->timeout = 160;
$response = $http->get('https://httpbin.org/get?website=tutorialspots.com',5);
 
var_dump($response);

Result:

bool(true)
array(2) {
  [0]=>
  array(8) {
    [0]=>
    string(15) "HTTP/1.1 200 OK"
    [1]=>
    string(35) "Date: Fri, 15 May 2020 08:36:46 GMT"
    [2]=>
    string(30) "Content-Type: application/json"
    [3]=>
    string(19) "Content-Length: 412"
    [4]=>
    string(17) "Connection: close"
    [5]=>
    string(23) "Server: gunicorn/19.9.0"
    [6]=>
    string(30) "Access-Control-Allow-Origin: *"
    [7]=>
    string(38) "Access-Control-Allow-Credentials: true"
  }
  [1]=>
  string(411) "{
  "args": {
    "website": "tutorialspots.com"
  }, 
  "headers": {
    "Content-Type": "application/x-www-form-urlencoded", 
    "Host": "httpbin.org", 
    "User-Agent": "Mozilla/5.0 (Windows NT 6.1; rv:8.0.1) Gecko/20100101 Firefox/8.0.1", 
    "X-Amzn-Trace-Id": "Root=1-5ebe549e-738d9974c33e9a06c2c7be1a"
  }, 
  "origin": "95.216.163.204", 
  "url": "https://httpbin.org/get?website=tutorialspots.com"
}"
}

Example 5: use SSH with HTTP connect

<?php

require "../http.php";

$http = new http;
$http->ssh('95.216.163.204','root:xxxxxxxxx');

$response = $http->get("http://httpbin.org/get?website=tutorialspots.com",5);

 
var_dump($response);

Result:

array(2) {
  [0]=>
  array(8) {
    [0]=>
    string(15) "HTTP/1.1 200 OK"
    [1]=>
    string(35) "Date: Fri, 15 May 2020 08:48:54 GMT"
    [2]=>
    string(30) "Content-Type: application/json"
    [3]=>
    string(19) "Content-Length: 411"
    [4]=>
    string(17) "Connection: close"
    [5]=>
    string(23) "Server: gunicorn/19.9.0"
    [6]=>
    string(30) "Access-Control-Allow-Origin: *"
    [7]=>
    string(38) "Access-Control-Allow-Credentials: true"
  }
  [1]=>
  string(410) "{
  "args": {
    "website": "tutorialspots.com"
  }, 
  "headers": {
    "Content-Type": "application/x-www-form-urlencoded", 
    "Host": "httpbin.org", 
    "User-Agent": "Mozilla/5.0 (Windows NT 6.1; rv:8.0.1) Gecko/20100101 Firefox/8.0.1", 
    "X-Amzn-Trace-Id": "Root=1-5ebe5776-bb5ecbd47eeb3eec0c1b738c"
  }, 
  "origin": "95.216.163.204", 
  "url": "http://httpbin.org/get?website=tutorialspots.com"
}"
}

Example 6: use SSH with HTTPS connect

<?php

require "../http.php";

$http = new http;
$http->ssh('95.216.163.204','root:xxxxxxxxx');

$response = $http->get("https://httpbin.org/get?website=tutorialspots.com",5);

 
var_dump($response);

Result:

array(2) {
  [0]=>
  array(8) {
    [0]=>
    string(15) "HTTP/1.1 200 OK"
    [1]=>
    string(35) "Date: Fri, 15 May 2020 08:51:23 GMT"
    [2]=>
    string(30) "Content-Type: application/json"
    [3]=>
    string(19) "Content-Length: 434"
    [4]=>
    string(17) "Connection: close"
    [5]=>
    string(23) "Server: gunicorn/19.9.0"
    [6]=>
    string(30) "Access-Control-Allow-Origin: *"
    [7]=>
    string(38) "Access-Control-Allow-Credentials: true"
  }
  [1]=>
  string(433) "{
  "args": {
    "website": "tutorialspots.com"
  }, 
  "headers": {
    "Accept": "*/*", 
    "Content-Type": "application/x-www-form-urlencoded", 
    "Host": "httpbin.org", 
    "User-Agent": "Mozilla/5.0 (Windows NT 6.1; rv:8.0.1) Gecko/20100101 Firefox/8.0.1", 
    "X-Amzn-Trace-Id": "Root=1-5ebe580b-58c9d5e2b88df18873b8bff2"
  }, 
  "origin": "95.216.163.204", 
  "url": "https://httpbin.org/get?website=tutorialspots.com"
}"
}

Leave a Reply