Question

Having a problem with trying to do an fopen on php. I'm sending across a data set of about 300kb to a Generic Handler (.ashx file). A solution on either the .Net or PHP side would be welcome. The code I'm using to send:

function DoPostRequest($url, $data, $optional_headers = null)
{
    $params = array('http' => array('method' => 'POST', 'content' => $data, 'header' => "Content-type: application/x-www-form-urlencoded\r\n" .
                    "Content-Length: " . strlen ( $data ) . "\r\n"));
    if($optional_headers != null) {
        $params['http']['header'] = $optional_headers;
    }
    $ctx = stream_context_create($params);
    try {
        ini_set ('user_agent', $_SERVER['HTTP_USER_AGENT']);
        $fp = fopen($url, 'rb', false, $ctx);
        $response = stream_get_contents($fp);
    } catch (Exception $e) {
      echo 'Exception: '.$e->getMessage();
    }
    return $response;
}

This contacts a web server running .Net. The problem is that once the request starts, the .Net server sends a HTTP 1.1 / 100 Continue response. Everything works fine at a smaller data set being sent, but I'm assuming that because the file size is large a Continue is automatically put in by the .Net Framework.

I've tried setting the C# code with

System.Net.ServicePointManager.Expect100Continue = false;

and also changed the Web.config file to include:

<system.net>
  <settings>
    <servicePointManager expect100Continue="false" />
  </settings>
</system.net>

None of this has worked, though. Therefore I'd like to do it on the PHP side. I'm using a vanilla PHP installation (no cURL installed), is there any way to get the fopen to ignore or expect the 100 continue?

EDIT: Full error code given:

Warning: fopen(http://localhost:59396/Testing.ashx) [function.fopen]: failed to open stream: HTTP request failed! HTTP/1.1 100 Continue in C:\xampp\htdocs\Prototype\Testing.php on line 72

Was it helpful?

Solution

OK, I've fixed this on my own. By changing the server to use IIS Express rather than the built-in Visual Studio emulator, everything worked fine. Oh well!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top