I am trying to post an image file to a server. Initially I tested my script without proxy at my home and it worked fine. But when I used the same script in my college it is throwing some error. The function for uploading images is as below

function upload($filepath,$dir)

$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_PROXY, 'localhost:7777');  
curl_setopt($ch, CURLOPT_PROXYUSERPWD, 'ae07b026:kpack');   
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible;)");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_URL, 'http://finalytics.in/sites/scrap/uploader.php' );
$post_array = array(
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_array); 
$response = curl_exec($ch);
echo $response; 


and uploader.php is a normal file which just saves the image.

The error which I am getting is like this


The requested URL could not be retrieved

While trying to process the request:

POST /sites/scrap/uploader.php HTTP/1.1 Proxy-Authorization: Basic YWUwN2IwMjY6a3BhY2s= User-Agent: Mozilla/4.0 (compatible;) Host: finalytics.in Accept: / Proxy-Connection: Keep-Alive Content-Length: 87022 Expect: 100-continue Content-Type: multipart/form-data; boundary=----------------------------07ae68105e71

The following error was encountered:

Invalid Request 

Some aspect of the HTTP Request is invalid. Possible problems:

Missing or unknown request method
Missing URL
Missing HTTP Identifier (HTTP/1.0)
Request is too large
Content-Length missing for POST or PUT requests
Illegal character in hostname; underscores are not allowed 

Your cache administrator is webmaster. Generated Sun, 05 Jun 2011 17:26:33 GMT by proxy1.iitm.ac.in (squid/2.7.STABLE7)


Just a guess, but is your college proxy really on your localhost?

Written by konsolenfreddy

its not, Im tunneling academic proxy and using it.

Written by Napster


Written by Napster

Accepted Answer

Thank god. You know its a great relief to find the solution. I am really happy now. its like taking 100 tons of load off my shoulders.

The problem is the proxy out institute using is "SQUID". And Squid doesn't support Expect: 100-continue.

So finally added this to my options

curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));

and its all working fine.

Written by Napster
This page was build to provide you fast access to the question and the direct accepted answer.
The content is written by members of the stackoverflow.com community.
It is licensed under cc-wiki