簡體   English   中英

將文件錯誤上傳到IIS7 + PHP服務器

[英]Upload File Error to IIS7 + PHP Server

我的IIS7在帶有PHP 5.4的Windows Server 2008 R2上運行。 我創建了一個網站,該網站使用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

哦,男孩...我真的很傻。 temp文件夾上的權限問題。 我確實將IIS服務帳戶添加到temp文件夾的安全設置中,但是我忘記添加權限。 = P

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM