这是我在onedrive中创建会话和上传文件的代码
string url = "https://api.onedrive.com/v1.0/drive/root:/" + "Nopbackup" +":/" + "" + fileName +":/upload.createSession" + "";
var result = string.Empty;
WebRequest request = WebRequest.Create(url);
request.Method = "POST";
//request.ContentType = "application/json";
request.ContentType = "contentType";
//request.ac = "application/json";
request.Headers.Add("Authorization", tokenType + " " + accessToken);
request.ContentLength = 0;
//byte[] requestData = Encoding.UTF8.GetBytes(url);
//using (Stream st = request.GetRequestStream())
// st.Write(requestData, 0, requestData.Length);
WebResponse response = request.GetResponse();
using (var streamReader = new StreamReader(response.GetResponseStream()))
result = streamReader.ReadToEnd();
它给服务器错误请求400错误
答案 0 :(得分:0)
我认为问题是你正在发布的网址。它看起来像这样:
string url = "https://api.onedrive.com/v1.0/drive/root:/" + "Nopbackup" +":/" + "" + fileName +":/upload.createSession" + "";
原来是
https://api.onedrive.com/v1.0/drive/root:/Nopbackup:/filename:/upload.createSession
你的冒号语法有点乱,而且API不知道该怎么做(因此是错误的请求)。
尝试构建类似这样的网址:
string url = "https://api.onedrive.com/v1.0/drive/root:/" + "Nopbackup" + "/" + fileName +":/upload.createSession";
我认为事情对你来说会更好。