七牛:总是return "405 Not Allowed"

Qiniu : Always return "405 Not Allowed"

我正在尝试集成七牛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>

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

如果您使用 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>

phpsdk已经提供了accesstoken功能。 Auth class 在这里: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;

希望对您有所帮助