Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3601956
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:41:07+00:00 2026-05-18T20:41:07+00:00

I have spent 3 days & 4 SO questions trying to fix something which

  • 0

I have spent 3 days & 4 SO questions trying to fix something which didn’t have a problem in the first place. However, the actual problem now has me stumped. Please see the following curl code. It correctly fetches a particular webpage and displays. There is a commented line (no. 8), which sets an additional POST variable. If I uncomment it, then the browser tries to download a gzip file instead of displaying it. I don’t know the correlation between that line and the strange behaviour at all.

(Note: I have used a static url from w3schools so others can try this code. I am trying to use this code for my own internal data server and proxy, and am facing exactly same issue. Uncommenting that particular line results in the strange behaviour. I need to use this variable. I don’t presently know a work-around plus am very curious to find the cause).

<?php
session_start();

$i_var_prefix="i_var_";

// Other important client dependent 'SERVER' variables.
if(isset($_SERVER['HTTPS'])) { $_POST["${i_var_prefix}_HTTPS"]=$_SERVER['HTTPS']; };
//if(isset($_SERVER['REMOTE_ADDR'])) { $_POST["${i_var_prefix}_REMOTE_ADDR"]=$_SERVER['REMOTE_ADDR']; };
// STRANGE PROBLEM:: IF I UNCOMMENT THE LINE ABOVE, THEN THE BROWSER DOES NOT DISPLAY THE CONTENT BUT TRIES TO DOWNLOAD IT.

$curl_url="http://www.w3schools.com/TAGS/form_action.asp";


// Set values of these header variables as got from client
$field_array= array(
      'Accept' => 'HTTP_ACCEPT',
      'Accept-Charset' => 'HTTP_ACCEPT_CHARSET',
      'Accept-Encoding' => 'HTTP_ACCEPT_ENCODING',
      'Accept-Language' => 'HTTP_ACCEPT_LANGUAGE',
      'Connection' => 'HTTP_CONNECTION',
      'Host' => 'HTTP_HOST',
      'Referer' => 'HTTP_REFERER',
      'User-Agent' => 'HTTP_USER_AGENT'
      );

$curl_request_headers=array();

foreach ($field_array as $key => $value) {
   if(isset($_SERVER["$value"])) {
      $server_value=$_SERVER["$value"];
      $curl_request_headers[]="$key: $server_value";
   }
};

//------
session_write_close();

//Open connection
$curl_handle = curl_init();
curl_setopt($curl_handle,CURLOPT_COOKIE,session_name()."=".session_id().";");
//Set the url, number of POST vars, POST data
curl_setopt($curl_handle, CURLOPT_URL, $curl_url);
curl_setopt($curl_handle, CURLOPT_POST, count($_POST));
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, $_POST);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_handle, CURLOPT_AUTOREFERER, TRUE);
curl_setopt($curl_handle, CURLOPT_HEADER, 1);
curl_setopt($curl_handle, CURLOPT_HTTPHEADER, $curl_request_headers);


//Execute post
$result = curl_exec($curl_handle);

//Close connection
curl_close($curl_handle);

list($headers,$content)=explode("\r\n\r\n",$result,2);
foreach (explode("\r\n",$headers) as $hdr) {
   header($hdr);
}
echo $content;
?>

UPDATE:

With the line uncommented, the result headers received are:

HTTP/1.1 100 Continue
HTTP/1.1 200 OK
Date: Wed, 22 Dec 2010 14:32:43 GMT
Server: Microsoft-IIS/6.0
MicrosoftOfficeWebServer: 5.0_Pub
X-Powered-By: ASP.NET
Content-Length: 478
Content-Type: text/html
Set-Cookie: ASPSESSIONIDSASCDCDT=KIIKANGALGLDJMLFHGPJBBOM; path=/
Cache-control: private

With the line commented out, result headers are:

HTTP/1.1 200 OK
Date: Wed, 22 Dec 2010 14:34:21 GMT
Server: Microsoft-IIS/6.0
MicrosoftOfficeWebServer: 5.0_Pub
X-Powered-By: ASP.NET
Content-Length: 478
Content-Type: text/html
Set-Cookie: ASPSESSIONIDSASCDCDT=JLPKANGAHDCNADBMNGHGIMCO; path=/
Cache-control: private

1) Why the difference?

2) How to handle the continue thing correctly?


SUMMARY:

The reason was that with that line, the number of POST variables increased to more than 1 and curl started automatically sending “Expect:” in header. This made the server respond with “Continue” header, which I was not handling.
I am using the solution posted below. The comments, specially Mchl’s comments – were very helpful in getting me in the right direction as I had no clue how that line could affect the behaviour.

regards,

JP

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T20:41:08+00:00Added an answer on May 18, 2026 at 8:41 pm

    Found one solution through some guesswork and searching. From http://matthom.com/archive/2008/12/29/php-curl-disable-100-continue-expectation. The 100-continue status is “expected” by default when using cURL-

    Expect: 100-continue.

    I disabled it using

    $curl_request_headers[]="Expect: ";.

    And now it works! (I guess server stops sending the continue header). (However, I am not convinced this is robust for all types of requests that the client can make [in the long run] but might be okay for normal purpose).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have spent several hours trying to find a means of writing a cross
I have spent too much time on this problem and am beginning to think
Ok so I've spent a couple hours trying to resolve this issue and have
I have spent the last few days attempting to integrate a Grails (version 1.3.2)
I spent the last three days trying to create a small app using SDL
I have been working now for few days on a small C program which
I've spent a couple of days trying to find out what's going on. I
I have spent lot of time doing research on VIM. I am Windows guy
A colleague and I have spent a few years developing a really cool Matlab
I spent days working on a function to get common chars in an array

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.