本文介绍了system.dll中出现'system.net.webexception'类型的异常,但未在用户代码中处理,服务器返回错误:(400)错误请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用每日动作API来上传视频但是当我选择10 mb或更大时,则10 mb文件会返回错误。
我是什么尝试过:
代码是
私有静态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(授权,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();
有人可以纠正错误。
解决方案
i am using daily motion API for uploading videos but when i choose 10 mb or greater then 10 mb file is returns the error.
What I have tried:
the code is
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; }
and the code where error is occurred is
var response = request.GetResponse();
some one could rectify the error .
解决方案
这篇关于system.dll中出现'system.net.webexception'类型的异常,但未在用户代码中处理,服务器返回错误:(400)错误请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!