note 27779 added to function.curl-setopt

From: Date: Wed, 18 Dec 2002 15:21:28 +0000
Subject: note 27779 added to function.curl-setopt
Groups: php.notes 
Request: Send a blank email to php-notes+get-41067@lists.php.net to get a copy of this message
I wrote a PHP script to transfer parameters to a photo server by GET or POST method. I use CURL function to do this. When I send the parameters by CUSTOMREQUEST option, the server return error because the script send the request twice. So I wrote another script saving remote image in local machine to validate this feature. The script segment as below --------------------------------- function saveImg($url,$referer) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); if($referer){ $host = getHost($url); $location = getLocation($url); $crqstring = ""; $crqstring .= "GET " .$location. " HTTP/1.1\r\n"; $crqstring .= "Accept: */*\r\n"; $crqstring .= "Referer: " .$referer. "\r\n"; $crqstring .= "Accept-Language: zh-cn\r\n"; $crqstring .= "Accept-Encoding: gzip, deflate\r\n"; $crqstring .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)\r\n"; $crqstring .= "Host: ".$host."\r\n"; $crqstring .= "Connection: Keep-Alive\r\n"; $crqstring .= "Cache-Control: no-cache\r\n\r\n"; curl_setopt($ch, CURLOPT_CUSTOMREQUEST,$crqstring); } curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_BINARYTRANSFER,1); $Data = curl_exec($ch); curl_close($ch); ...... } ------------------------------ In script, I call this function as $url = "http://www.php.net/gifs/php_snow.gif"; $referer = "http://www.php.net/"; saveImg($url, $referer); Although it return the result correctly, it does send the request twice. Conclusively, it is not send the request twice. Below is Sniffer decode. ------------------------------------ HTTP: ---- Hypertext Transfer Protocol ---- HTTP: HTTP: Line 1: GET /gifs/php_snow.gif HTTP/1.1 HTTP: Line 2: Accept: */* HTTP: Line 3: Referer: http://www.php.net/ HTTP: Line 4: Accept-Language: zh-cn HTTP: Line 5: Accept-Encoding: gzip, deflate HTTP: Line 6: User-Agent: Mozilla/4.0 (compatibal; MSIE 6.0 Windows NT5. HTTP: 0) HTTP: Line 7: Host: www.php.net HTTP: Line 8: Connection: Keep-Alive HTTP: Line 9: Cache-Control: no-cache HTTP: Line 10: HTTP: Line 11: /gifs/php_snow.gif HTTP: Line 12: Host: www.php.net HTTP: Line 13: Progma: no-cache HTTP: Line 14: Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, HTTP: */* HTTP: Line 15: HTTP: ----------------------------------------- I don't know that what bring to this feature or it's a bug of CURL. Someone would like to tell me? -- http://www.php.net/manual/en/function.curl-setopt.php http://master.php.net/manage/user-notes.php?action=edit+27779 http://master.php.net/manage/user-notes.php?action=delete+27779 http://master.php.net/manage/user-notes.php?action=reject+27779

« previous php.notes (#41067) next »