cURL / Mailing Lists / curl-and-php / Single Mail

curl-and-php

Server reacting to CURLOPT_NOBODY.

From: Jake Cattrall <contact_at_websiteforge.co.uk>
Date: Fri, 24 Aug 2012 19:51:19 +0100

So here we are post-requesting from
http://www.fileflyer.com/view/G67S0KEVQQKFp

Here is the code:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://www.fileflyer.com/view/G67S0KEVQQKFp
");
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-type:
application/x-www-form-urlencoded"));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data); // valid from form1 at the url
above.
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; rv:8.0.1)
Gecko/20100101 Firefox/8.0.1");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
if($_POST['showbody'] == 0){

curl_setopt($ch, CURLOPT_NOBODY, 1);

}
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt" ); // writable
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt" );
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
curl_setopt( $ch, CURLOPT_HTTPHEADER, array( 'Expect:' ) ); // put in place
to prevent 100-continue forced header.
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
$c = curl_exec($ch);
if($_POST['showbody'] == 0){

echo "<h1>Response</h1>";

echo $c;

}else{

echo "<h1>Response</h1>";

echo curl_exec($c);

file_put_contents("view.html",$c);

echo "<a href='view.html' target=_new>View</a>";

}
curl_close($ch);

So, looking that this code, one outcome shows only the headers on the
screen, and the other writes the full response including body into a file
called view.html.

However, it only writes the response header, and even that is totally
different to just requesting a header.

*Check it out with nobody enabled (Works fine):*

*Response

HTTP/1.1 200 OK Cache-Control: private Content-Length: 40446 Content-Type:
text/html; charset=utf-8 Server: Microsoft-IIS/7.5 X-AspNet-Version:
2.0.50727 X-Powered-By: ASP.NET Date: Fri, 24 Aug 2012 17:28:52 GMT

Request

**POST /view/G67S0KEVQQKFp HTTP/1.1 User-Agent: Mozilla/5.0 (Windows NT
6.1; rv:8.0.1) Gecko/20100101 Firefox/8.0.1 Host: www.fileflyer.com Accept:
*/* Cookie: WebID=0634d0db-ceaf-4da8-854f-d028125a0d48; MID=239986038;
ASP.NET_SessionId=bjvvfqm3vze2qlzwvxqi4bnp Content-Length: 8258
Content-Type: application/x-www-form-urlencoded*

*And with nobody disabled:*
*Response**HTTP/1.1 200 OK Cache-Control: private Content-Length: 0 Server:
Microsoft-IIS/7.5 X-AspNet-Version: 2.0.50727 X-Powered-By: ASP.NET Date:
Fri, 24 Aug 2012 17:33:02 GMT*
*Request**POST /view/G67S0KEVQQKFp HTTP/1.1 User-Agent: Mozilla/5.0
(Windows NT 6.1; rv:8.0.1) Gecko/20100101 Firefox/8.0.1 Host:
www.fileflyer.com Accept: */* Cookie:
WebID=0634d0db-ceaf-4da8-854f-d028125a0d48; MID=239986038;
ASP.NET_SessionId=bjvvfqm3vze2qlzwvxqi4bnp Content-Length: 8258
Content-Type: application/x-www-form-urlencoded*
*
*
*
*
I notice the server is also acting strange on other pages, one returning a
404 instead of a file.

Can anyone explain why the server is somehow reacting to the differences in
my curl configuration?

_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
Received on 2012-08-24