2013-04-09 93 views
4

我正在使用Azure網站構建簡單的PHP Web服務,並且無法使其支持PUT和DELETE http方法。假設這是必須進入web.config文件的東西 - 我已經嘗試了一些來自interwebs的選項,但它們中的一些看起來沒有正常工作。有任何想法嗎?Azure網站PHP API - 405方法不允許使用PUT和DELETE

這裏的web.config文件,因爲它目前爲:

<?xml version="1.0" encoding="UTF-8"?> 
<configuration> 
    <system.webServer> 
    <handlers> 
    </handlers> 
    <security> 
    </security> 
    <directoryBrowse enabled="false" /> 
    <caching> 
     <profiles> 
     <add extension=".php" policy="DontCache" kernelCachePolicy="DontCache" /> 
     <add extension=".html" policy="CacheForTimePeriod" kernelCachePolicy="CacheForTimePeriod" duration="14:00:00" /> 
     </profiles> 
    </caching> 
    <rewrite> 
     <rules> 
     <rule name="block favicon" stopProcessing="true"> 
      <match url="favicon\.ico" /> 
      <action type="CustomResponse" statusCode="404" subStatusCode="1" 
      statusReason="The requested file favicon.ico was not found" 
      statusDescription="The requested file favicon.ico was not found" /> 
     </rule> 
     <rule name="Cols Rule" stopProcessing="true"> 
      <match url="^(.*)$" ignoreCase="false" /> 
      <conditions> 
      <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" /> 
      <add input="{URL}" pattern="^/favicon.ico$" ignoreCase="false" negate="true" /> 
      <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" /> 
      </conditions> 
      <action type="Rewrite" url="index.php?q={R:1}" appendQueryString="true" /> 
     </rule> 
     </rules> 
    </rewrite> 
    <defaultDocument> 
     <files> 
     <remove value="index.php" /> 
     <add value="index.php" /> 
     </files> 
    </defaultDocument> 
    </system.webServer> 
</configuration> 
+0

幾天前我看到了類似的線程。在這種情況下,事實證明PUT動詞被內部網絡阻塞。你能檢查一下,這是不是這種情況? – 2013-04-09 17:36:36

回答

3

我沒有看到你有處理程序加入到你的web.config。我沒有親自測試過,但有人建議PUT和DELETE應該可以與Windows Azure網站一起使用,但是您需要通過web.config在Windows Azure網站上正確配置它們。

以下是簡單的配置,你可以用它來設置它:

<configuration> 
<system.webServer> 
    <handlers> 
     <remove name="PHP53_via_FastCGI" /> 
     <add name="PHP53_via_FastCGI" path="*.php" 
       verb="GET, PUT, POST, HEAD, DELETE" 
       modules="FastCgiModule" 
       scriptProcessor="D:\Program Files (x86)\PHP\v5.3\php-cgi.exe" 
       resourceType="Either" requireAccess="Script" /> 
    </handlers> 
</system.webServer> 
</configuration> 
+0

<除去名稱= 「PHP54_via_FastCGI」/> <添加名稱= 「PHP54_via_FastCGI」 路徑= 「*。PHP」 動詞= 「GET,PUT,POST,DELETE,HEAD」 模塊= 「FastCgiModule」 scriptProcessor = 「D:\ Program Files(x86)\ PHP \ v5.4 \ php-cgi.exe」 resourceType =「要麼」requireAccess =「Script」/> 2013-04-10 11:25:44

+0

這篇文章做的很好,覆蓋了Windows Azure網站上的配置http://blog.maartenballiauw.be/post/2012/07/09/Tweaking-Windows-Azure-Web-Sites.aspx – 2013-05-02 20:43:38

3

它沒有與DELETE工作作爲最後的選擇,這裏是修改PHP54在Azure上的代碼。但是要感謝Avkash!

<handlers> 
    <remove name="PHP54_via_FastCGI" /> 
     <add name="PHP54_via_FastCGI" path="*.php" 
       verb="GET, PUT, POST, DELETE, HEAD" 
       modules="FastCgiModule" 
       scriptProcessor="D:\Program Files (x86)\PHP\v5.4\php-cgi.exe" 
       resourceType="Either" requireAccess="Script" /> 
    </handlers> 
+5

現在HEAD是最後一個選項,它停止工作。我在HEAD之後添加了一個逗號,現在它再次運行。奇怪的。 – 2014-03-31 20:12:14

+0

不錯,謝謝..添加一個假人也適用。 – 2015-09-24 11:27:03