类型' System.Net.WebException'的例外情况发生在System.dll但未在用户代码中处理,服务器返回错误:(400)错误请求

时间:2016-04-18 05:43:15

标签: c# asp.net-mvc dailymotion-api

我正在使用每日动作API上传视频,但是当我选择大小为10 mb或更大的文件时,会出现错误。代码是

private static UploadedResponse PublishVideo(UploadResponse uploadResponse, string accessToken)
        {
            var request = WebRequest.Create("https://api.dailymotion.com/me/videos?url=" + HttpUtility.UrlEncode(uploadResponse.url));
            request.Method = "POST";
            request.ContentType = "application/x-www-form-urlencoded";
            request.Headers.Add("Authorization", "OAuth " + accessToken);

        var requestString = String.Format("title={0}&tags={1}&channel={2}&published={3}",
            HttpUtility.UrlEncode("Some new Title"),
            HttpUtility.UrlEncode("Tags"),
            HttpUtility.UrlEncode("news"),
            HttpUtility.UrlEncode("true"));

        var requestBytes = Encoding.UTF8.GetBytes(requestString);

        var requestStream = request.GetRequestStream();

        requestStream.Write(requestBytes, 0, requestBytes.Length);

        var response = request.GetResponse();

        var responseStream = response.GetResponseStream();
        string responseString;
        using (var reader = new StreamReader(responseStream))
        {
            responseString = reader.ReadToEnd();
        }

        var uploadedResponse = JsonConvert.DeserializeObject<UploadedResponse>(responseString);
        return uploadedResponse;
    }

此行发生错误

  var response = request.GetResponse();
有人纠正错误?

0 个答案:

没有答案