0

我在带有 PHP 5.4 的 Windows Server 2008 R2 上运行 IIS7。我创建了一个带有 SSL 加密的网站,其中包含上传和下载文件的 PHP 脚本。我还使用 Visual Studio 2012 (C#) 创建了一个客户端应用程序,该应用程序使用 WebClient 对象来执行上传/下载。下载工作完美。但是,当我尝试上传文件(使用 WebClient)时,会发生 WebException:

Message: The remote server returned an error: (500) Internal Server Error.
Status: System.Net.WebExceptionStatus.ProtocolError
InnerException: null;

PHP上传脚本目前是空白的(文件要上传到服务器的临时目录,然后自动删除)。我应该补充一点,我能够在我的浏览器中运行 PHP 脚本而不会出现任何错误(即不上传任何内容)。一开始我以为可能是IIS服务账号没有访问临时目录的权限,但是添加显式权限并没有解决问题。有任何想法吗?

我的 C# 代码如下:

public static void UploadFile(Uri uri)
{
    try
    {
        using (WebClient client = new WebClient())
        {
            // Ignore SSL warnings due to unsigned certificate.
            ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(delegate { return true; });

            client.Credentials = CredentialCache.DefaultNetworkCredentials;

            // Get a path/name of a new temporary file.
            String tempFile = Path.GetTempFileName();

            // Create a 1KB temporary file.
            using (var fileStream = new FileStream(tempFile, FileMode.Create, FileAccess.Write))
            {
                fileStream.SetLength(1024);

            }

            // Upload the file to the server.
            client.UploadFile(uri, tempFile);

            // Delete temporary file.
            File.Delete(tempFile);

        }

    }
    catch (WebException ex)
    {
        MessageBox.Show(ex.ToString());

    }

}

更新 1 - IIS 日志文件

2013-02-04 17:05:05 155.14.123.53 POST /Archive/uploadTest.php - 443 - 155.14.123.208 - 401 2 5 0
2013-02-04 17:05:05 155.14.123.53 POST /Archive/uploadTest.php - 443 HYPER\JOHNSD 155.14.123.208 - 500 0 0 15
4

1 回答 1

0

哦,男孩……我真的觉得自己很愚蠢。这临时文件夹的权限问题。我确实将 IIS 服务帐户添加到临时文件夹的安全设置中,但我忘记添加权限。=P

于 2013-02-04T17:35:18.950 回答