August 2011
Intermediate to advanced
546 pages
20h 53m
English
A GET request is one of the most straightforward request types. You are simply making a request to a URI endpoint and expecting some data to be returned to you.
In PHP, we can use a simple cURL request:
<?php $url = 'http://www.example.com/request.php'; $ch = curl_init($url); $options = array( CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => 1 ); curl_setopt_array($ch, $options); $response = curl_exec($ch); curl_close($ch); ?>
Within the cURL option, we are specifying that we want to call a
specific URL (CURLOPT_URL) and would like to
receive the response data from the request (CURLOPT_RETURNTRANSFER).
In Python, we can simply use urllib from the standard library:
import urllib url = 'http://www.example.com/request.py' f = urllib.urlopen(url) response = f.read()
We open the specified URL and then read back the response from the request.
Read now
Unlock full access