【问题标题】:Qiniu : Always return "405 Not Allowed"七牛:总是返回“405 Not Allowed”
【发布时间】:2016-02-23 18:50:47
【问题描述】:

我正在尝试集成七牛 SDK 以进行音频上传。根据它的文档,我们首先需要获取访问令牌。 因为我们需要在任何 api 调用中传递 AccessToken。

http://developer.qiniu.com/docs/v6/api/reference/acc/access-token.html

我正在尝试使用以下数据调用 API。

host : http://acc.qbox.me
method : POST
Parameters : 
grant_type = password
username = <username>
password = <password>

但它仍然给我以下回应

<html>
<head><title>405 Not Allowed</title></head>
<body bgcolor="white">
<center><h1>405 Not Allowed</h1></center>
<hr><center>nginx/1.4.4</center>
</body>
</html>

请任何人都可以指导我其中有什么问题。

【问题讨论】:

  • 405 是不允许的方法。您确定您的服务支持 POST 吗?

标签: php ios afnetworking audio-streaming


【解决方案1】:

php sdk 提供了accesstoken 功能。 Auth 类在这里:https://github.com/qiniu/php-sdk/blob/master/src/Qiniu/Auth.php

在您的项目中,您应该需要此文件。 这里有很多例子:https://github.com/qiniu/php-sdk/tree/master/examples

这里是上传令牌示例:

<?php
 require_once '/path/to/autoload.php';
 use Qiniu\Auth;
 $accessKey = 'Access_Key';
 $secretKey = 'Secret_Key';     
 $auth = new Auth($accessKey, $secretKey);
 $bucket = 'Bucket_Name';
 $upToken = $auth->uploadToken($bucket);
 echo $upToken;

希望对你有帮助。

【讨论】:

  • 我在我的 Mac 上安装了 xampp。之后,我将“php-sdk-master”放在“htdocs”文件夹中。我通过更改 Accesskey 和 screteKey 来测试“download_token.php”。
  • 现在,我可以生成Accesstoken了。
【解决方案2】:

如果您使用 iOS 9 SDK,由于 ATP(应用程序传输安全),您的所有调用都应使用 https。如果您确实希望有例外并且需要允许特定的 http 调用,您应该将例外添加到您的 .plist 文件中:

key>NSAppTransportSecurity</key>
<dict>
    <key>NSExceptionDomains</key>
    <dict>
        <key>http://acc.qbox.me</key>
        <dict>
            <key>NSIncludesSubdomains</key>
            <false/>
            <key>NSExceptionAllowsInsecureHTTPLoads</key>
            <false/>
            <key>NSExceptionRequiresForwardSecrecy</key>
            <true/>
            <key>NSExceptionMinimumTLSVersion</key>
            <string>TLSv1.2</string>
            <key>NSThirdPartyExceptionAllowsInsecureHTTPLoads</key>
            <false/>
            <key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
            <true/>
            <key>NSThirdPartyExceptionMinimumTLSVersion</key>
            <string>TLSv1.2</string>
            <key>NSRequiresCertificateTransparency</key>
            <false/>
        </dict>
    </dict>
</dict>

您甚至可以通过将其添加到您的 .plist 文件中来允许所有 http 流量(但 Apple 不建议这样做):

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>

【讨论】:

  • 我还在 google crome store 的 POSTMAN 工具上进行了测试。它也给了我同样的结果
  • 尝试使用 https 而不是 http 调用它。通过 http 传递用户名和密码参数不是一个好主意,并且服务可能会通过返回 405 错误来阻止它。
猜你喜欢
  • 2016-10-16
  • 1970-01-01
  • 2011-09-25
  • 1970-01-01
  • 2021-06-14
  • 2016-12-04
  • 1970-01-01
  • 2014-09-03
  • 2014-04-09
相关资源
最近更新 更多