Azure网站PHP API - PUT和DELETE上不允许使用405方法

时间:2013-04-09 17:20:47

标签: azure web-config azure-web-sites http-method

我正在使用Azure网站构建一个简单的PHP Web服务,但我无法使其支持PUT和DELETE http方法。假设它必须进入web.config文件 - 我尝试了几个来自互联网的选项,但它们似乎没有正常运行。有什么想法吗?

这是目前的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>

2 个答案:

答案 0 :(得分:4)

我没有看到你的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>

答案 1 :(得分:4)

它不能与DELETE一起使用作为最后一个选项,这是在Azure上为PHP54修改的代码。但感谢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>