【发布时间】:2015-05-03 01:04:18
【问题描述】:
我想通过 CURL 从 PHP (v5.4) 将文件发送到 ASP.NET WebApi (C#)。我认为这应该很容易,但我遇到了一些我无法解释的奇怪行为:
php 脚本:
<?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>
当我使用大于 9mb 的文件(例如两个 5mb 文件)执行脚本时,根据文件的大小,几分钟后我会得到以下结果:
ErrorMsg: SSL read: error:00000000:lib(0):func(0):reason(0), errno 10054
ErrorNr.:56
当我更改为 9mb 或更小的文件时,一切正常。
另外:从 cmd (Windows 7) 调用 CURL 时出现同样的错误:
curl --form upload=@myfile.jpg --form press=OK https://localhost:44303/api/v1/File -k -sslv3
=> 一切都发生在我的本地机器上,所以没有防火墙也没有 vpn。
我尝试了多种参数组合,但没有任何进展。实际上,它比实际测试更多的是猜测。也许我一直忽略了一件小事?
提前非常感谢!
【问题讨论】:
标签: c# php asp.net curl file-upload