RE: Help

Nelson Johnson <[email protected]> Mon, 24 Oct 2011 05:50:12 +1200
Newsgroups gmane.comp.web.curl.php
Message-ID <[email protected]>
Hello David,

Thanks for your response. The script is in the attachment.

I think that the second request work. I'm trying around with cURL and want to load google just with cURL so the browser does not need
to do anything because everything was loaded by the server.

The problem is that the logo I want to display does not work.

Thanks for your help :)

Nelson


From: [email protected]
Subject: Re: Help
Date: Sun, 23 Oct 2011 13:02:15 -0400
To: [email protected]



Nelson,
I have some problems to understand cURL. I wrote a get request for google.com
This request is working fine but my browser Im using is sending some other requests too.

The request I wrote is: GET / HTTP/1.1 for http://www.google.com/
Now the browser does requests like:

GET /logos/2011/liszt11-hp.jpg HTTP/1.1

or

GET /generate_204 HTTP/1.1

How can I send these requests with cURL as well and echo the site then? 

Do you have code example??
David
_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php

_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
googleget.php (application/octet-stream, 4.5 KB)
<?php


$address = "http://www.google.de/";
$address2 = "http://clients1.google.de/generate_204";
$logo = "http://www.google.de/images/srpr/logo3w.png";



// einzelnen Cookies, später zusammengesetzt 
$pref = "PREF=ID=261421897545dde3:U=664c6b0e6c1efd54:FF=0:LD=de:NR=10:TM=1313968732:LM=1319380808:SG=2:S=hsFsAeYVc56EFDBm;";
$nid = "NID=52=D3IubWDI8Y5V7l3cM_mejbPn_VR55AqsMCE2qpzg-sBqVIkixM3bR_-p9R0mcpuwBIsu6axY-tYpLZ1lgyEZsXULA1pdTQkF1K2_AsgNXV4sYz4ZbxhJD0gTrXvC1fIz";


// Cookie.txt
$cookieFileLocation = "htdocs/loadtest/cookiegoogle.txt"; 

// useragent setzen
$useragent = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3'; 

// erzeuge einen neuen cURL-Handle
$ch1 = curl_init();

// header zusammensetzen und an CURLOPT_HTTPHEADER übergeben
$header[] = "Host: www.google.de";
$header[] = "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
$header[] = "Accept-Language: de-de,de;q=0.8,en-us;q=0.5,en;q=0.3";
$header[] = "Accept-Encoding: gzip,deflate";
$header[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7";
$header[] = "Keep-Alive: 115";
$header[] = "Connection: keep-alive";




// setze die URL und andere Optionen
curl_setopt($ch1, CURLOPT_URL, $address);
curl_setopt($ch1, CURLOPT_USERAGENT, $useragent);
curl_setopt($ch1, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch1, CURLOPT_HEADER, FALSE);
curl_setopt($ch1, CURLINFO_HEADER_OUT, TRUE);
curl_setopt($ch1, CURLOPT_NOBODY, FALSE);
curl_setopt($ch1, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch1, CURLOPT_COOKIEJAR,$cookieFileLocation);
curl_setopt($ch1, CURLOPT_COOKIEFILE,$cookieFileLocation);
curl_setopt($ch1, CURLOPT_ENCODING, 'gzip,deflate');
curl_setopt($ch1, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch1, CURLOPT_TIMEOUT, 25);
curl_setopt($ch1, CURLOPT_FRESH_CONNECT, TRUE);
curl_setopt($ch1, CURLOPT_COOKIE,$pref.'; '.$nid); 
curl_setopt($ch1, CURLOPT_FOLLOWLOCATION, TRUE);


// curl ausführen und header ausgeben

$response1 = curl_exec($ch1);

// erzeuge einen neuen cURL-Handle
$ch2 = curl_init();


// header zusammensetzen und an CURLOPT_HTTPHEADER übergeben
$header1[] = "Host: clients1.google.de";
$header1[] = "Accept: image/png,image/*;q=0.8,*/*;q=0.5";
$header1[] = "Accept-Language: de-de,de;q=0.8,en-us;q=0.5,en;q=0.3";
$header1[] = "Accept-Encoding: gzip,deflate";
$header1[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7";
$header1[] = "Keep-Alive: 115";
$header1[] = "Connection: keep-alive";





// setze die URL und andere Optionen
curl_setopt($ch2, CURLOPT_URL, $address2);
curl_setopt($ch2, CURLOPT_USERAGENT, $useragent);
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, TRUE);
curl_setopt($ch2, CURLOPT_HEADER, FALSE);
curl_setopt($ch2, CURLINFO_HEADER_OUT, TRUE);
curl_setopt($ch2, CURLOPT_NOBODY, FALSE);
curl_setopt($ch2, CURLOPT_HTTPHEADER, $header1);
curl_setopt($ch2, CURLOPT_COOKIEJAR,$cookieFileLocation);
curl_setopt($ch2, CURLOPT_COOKIEFILE,$cookieFileLocation);
curl_setopt($ch2, CURLOPT_ENCODING, 'gzip,deflate');
curl_setopt($ch2, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch2, CURLOPT_TIMEOUT, 25);
curl_setopt($ch2, CURLOPT_FRESH_CONNECT, TRUE);
curl_setopt($ch2, CURLOPT_REFERER, $address);
curl_setopt($ch2, CURLOPT_COOKIE,$pref.'; '.$nid); 
curl_setopt($ch2, CURLOPT_FOLLOWLOCATION, TRUE);


$response2 = curl_exec($ch2);


$ch3 = curl_init();

// setze die URL und andere Optionen
curl_setopt($ch3, CURLOPT_URL, $logo);
curl_setopt($ch3, CURLOPT_USERAGENT, $useragent);
curl_setopt($ch3, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch3, CURLOPT_BINARYTRANSFER, TRUE);
curl_setopt($ch3, CURLOPT_HEADER, FALSE);
curl_setopt($ch3, CURLINFO_HEADER_OUT, TRUE);
curl_setopt($ch3, CURLOPT_NOBODY, FALSE);
curl_setopt($ch3, CURLOPT_HTTPHEADER, $header1);
curl_setopt($ch3, CURLOPT_COOKIEJAR,$cookieFileLocation);
curl_setopt($ch3, CURLOPT_COOKIEFILE,$cookieFileLocation);
curl_setopt($ch3, CURLOPT_ENCODING, 'gzip,deflate');
curl_setopt($ch3, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch3, CURLOPT_TIMEOUT, 25);
curl_setopt($ch3, CURLOPT_FRESH_CONNECT, TRUE);
curl_setopt($ch3, CURLOPT_REFERER, $address);
curl_setopt($ch3, CURLOPT_COOKIE,$pref.'; '.$nid); 
curl_setopt($ch3, CURLOPT_FOLLOWLOCATION, TRUE);


$response3 = curl_exec($ch3);

// response header ausgeben
echo ($response1);
echo ($response2);
echo ($response3);


// schließe den cURL-Handle und gebe die Systemresourcen frei
curl_close($ch1);
curl_close($ch2);
curl_close($ch3);


?>