I want to send a file from PHP (v5.4) via CURL to an ASP.NET WebApi (C#). I thought this should be easy but I'm facing some strange behaviour I can't explain:
php script:
<?php
$files = array();
$files['file_content'] = '@'.realpath('./myfile.jpg');
$url = 'https://localhost:44307/api/v1/File';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, trim($url));
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $files);
curl_setopt($ch, CURLOPT_SSLVERSION, 3);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_NOPROGRESS, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// ignore ssl verifyer
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_exec($ch);
echo 'ErrorMsg: '.curl_error($ch).'<br>';
echo "ErrorNr.:".curl_errno($ch).'<br>';
curl_close($ch);
?>
php.ini:
upload_max_filesize = 1024M
max_file_uploads = 20
memory_limit = 1024M
post_max_size = 1024M
Web.config:
<system.web>
<httpRuntime executionTimeout="1800" maxRequestLength="2097152" requestValidationMode="2.0" />
</system.web>
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="2147483648" />
</requestFiltering>
</security>
</system.webServer>
When I execute the script with an file bigger than 9mb (also with e.g. two 5mb-files) I get the following result after a few minutes depending on the size of the file:
ErrorMsg: SSL read: error:00000000:lib(0):func(0):reason(0), errno 10054
ErrorNr.:56
When I change to an file of 9mb or less everything works fine.
Also: I get the same error when calling CURL from cmd (Windows 7):
curl --form upload=@myfile.jpg --form press=OK https://localhost:44303/api/v1/File -k -sslv3
=> Everything happens on my local machine, so no firewall and no vpn.
I have tried multiple combinations of parameters but I don't make any progress. Actually it is more guessing than real testing. Maybe there is just one little thing I overlooked all the time?
Thanks a lot in advance!