Home > Article > Backend Development > How to Emulate a Web Browser\'s GET Request with Curl?
Emulating a Web Browser's GET Request with Curl
When attempting to retrieve web pages using curl, you may encounter errors that seem to stem from unrecognized or unfulfilled request headers. This is because curl does not natively emulate a web browser's GET request headers.
To properly simulate a web browser, follow these steps:
Configure User Agent:
Handle Cookies (Optional):
Verify SSL Certificate:
Set Verbose Mode:
Example Code:
<code class="php">$url = "https://new.aol.com/productsweb/subflows/ScreenNameFlow/AjaxSNAction.do?s=username&f=firstname&l=lastname"; $agent = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322)'; $ch = curl_init(); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_VERBOSE, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_USERAGENT, $agent); curl_setopt($ch, CURLOPT_URL, $url); $result = curl_exec($ch); var_dump($result);</code>
The above is the detailed content of How to Emulate a Web Browser\'s GET Request with Curl?. For more information, please follow other related articles on the PHP Chinese website!