- PEAR (HTTP_Request)
See the code samples below.Code: Select all
<?php require_once "HTTP/Request.php"; $req =& new HTTP_Request("https://robot.lk/"); if (!PEAR::isError($req->sendRequest())) { echo $req->getResponseBody(); } ?>
Code: Select all
<?php require_once "HTTP/Request.php"; $req =& new HTTP_Request("https://robot.lk"); $req->setMethod(HTTP_REQUEST_METHOD_POST); $req->addPostData("Foo", "bar"); if (!PEAR::isError($req->sendRequest())) { $response1 = $req->getResponseBody(); } else { $response1 = ""; } echo $response1; ?>
- cURL
Code: Select all
$url = "https://robot.lk/"; $request = curl_init(); curl_setopt($request,CURLOPT_URL,$url); curl_setopt($request, CURLOPT_RETURNTRANSFER, 1); $response = curl_exec($request); curl_close($request);
How to do a http request using php
How to do a http request using php
There are two ways of doing this with php.