Php curl automatically set body in HTTP GET request -
here issue. have 3 environments (apache + mysql + mongodb) : continuous integration, uat , prod.
all 3 environments on different vm hosted on same proxmox , accessible through nginx server.
i use php curl download csv files. particular csv file provider, php curl not achieve download file on continuous intergration environment while on uat , prod. after hours of investigation, closest came problem, guess, outputting request header.
as can see below, on continuous integration environment, php curl set "content-length" header suggest sending body within request. have not been able debug request body now.
i don't understand why php curl add request body on ci environment when not in uat , prod env.
i joined php curl setup code.
any appreciated :)
(request header in continuous integration env) ------------------------------------------ http/1.1 413 request entity large date: mon, 15 dec 2014 21:01:22 gmt server: apache content-length: 341 connection: close content-type: text/html; charset=iso-8859-1 <!doctype html public "-//ietf//dtd html 2.0//en"> <html><head> <title>413 request entity large</title> </head><body> <h1>request entity large</h1> requested resource<br />/export/export<br /> not allow request data requests, or amount of data provided in request exceeds capacity limit. </body></html> ----------------------------------------- (request header uat env) ------------------------------------------ http/1.1 200 ok date: mon, 15 dec 2014 21:05:35 gmt server: apache connection: close transfer-encoding: chunked content-type: text/plain; charset=utf-8 + csv data ----------------------------------------------
php curl setup code :
public function getresource($url, $outputheaders = false, $timeout = false) { $ch = curl_init($url); curl_setopt ($ch, curlopt_returntransfer, true); curl_setopt($ch, curlopt_useragent, 'mozilla/5.0 (windows nt 6.1; wow64) applewebkit/537.36 (khtml, gecko) chrome/30.0.1599.69 safari/537.36'); // follow redirections curl_setopt($ch, curlopt_followlocation, true); // use navigation cookies $cookiefilepath = app . 'tmp' . ds . 'cookies' . ds . 'curl_cookie.txt'; curl_setopt($ch, curlopt_cookiefile, $cookiefilepath); curl_setopt($ch, curlopt_cookiejar, $cookiefilepath); // trust certificate curl_setopt($ch, curlopt_ssl_verifypeer, false); if ($timeout) { curl_setopt($ch, curlopt_connecttimeout, 30); curl_setopt($ch, curlopt_timeout, 30); } if($outputheaders) curl_setopt($ch, curlopt_header, 1); $data = curl_exec($ch); if(curl_errno($ch)) { throw new exception('erreur curl : ' . curl_error($ch)); } if(empty($data)) throw new exception('curl returned empty html page.'); $encoding = self::getencoding($ch, $data); $html['data'] = $data; $html['encoding'] = $encoding; $html['effective_url'] = curl_getinfo($ch, curlinfo_effective_url); curl_close($ch); return $html; }
first thing, not outputting request header response one.
i installed mitm proxy (http://mitmproxy.org/ - easy install, easy use) allows traffic monitoring terminal , see curl sending cookies when requesting continuous integration environment not sending uat environment.
removing sent cookies on continuous integration environment solved issue.
Comments
Post a Comment