0

我正在使用下面的 url 使用 oauth 将文件上传到保管箱,但出现错误 {“error”:“调用需要以下方法之一:PUT,POST,得到 GET!”} 将 httpmethod 作为 PUT 传递,但仍然询问错误.

用于上传的签名是

https://api-content.dropbox.com/1/files_put/dropbox/test?oauth_consumer_key=twcek2m7cxtantc&oauth_signature_method=PLAINTEXT&oauth_token=918v4lxg2w23car&oauth_version=1.0&oauth_signature=fbs34nykryouuj1%26rbbprgh95tjzf22

使用这个我得到了错误

{"error": "调用需要以下方法之一:PUT、POST、得到 GET!"}

请告诉我如何解决此错误。

public FileSystemInfo UploadFile(string root, string path, string file)
        {
            var uri = new Uri(new Uri(DropboxRestApi.ApiContentServer),
                String.Format("files_put/{0}/{1}",
                root, UpperCaseUrlEncode(path)));

            var oauth = new OAuth();
            //var requestUri = oauth.DownloadSignRequest(uri, _consumerKey, _consumerSecret, "POST", _accessToken);
            var requestUri = oauth.SignRequest(uri, _consumerKey, _consumerSecret, _accessToken, "PUT");

            var request = (HttpWebRequest) WebRequest.Create(requestUri);
            request.Method = WebRequestMethods.Http.Post;
            request.KeepAlive = true;

            byte[] buffer;
            using (var fileStream = new FileStream(file, FileMode.Open, FileAccess.Read))
            {
                int length = (int) fileStream.Length;
                buffer = new byte[length];
                fileStream.Read(buffer, 0, length);
            }

            request.ContentLength = buffer.Length;
            using (var requestStream = request.GetRequestStream())
            {
                requestStream.Write(buffer, 0, buffer.Length);
            }

           // request.Method = "POST";

            var response = request.GetResponse();
            var reader = new StreamReader(response.GetResponseStream());
            var json = reader.ReadToEnd();
            return ParseJson<FileSystemInfo>(json);
        }
4

1 回答 1

0

我在保存要上传的文件的路径时出错。

为保存在路径中提供相同的文件名。

就这样。

于 2013-01-31T15:33:39.033 回答