2016-05-14 44 views
0

这是我的代码为onedrive一个驱动器REST API服务器错误请求400上传文件

  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

不知道您正在调用的服务的细节,但将ContentType作为ContentTipe并将ContentLength设为零可能是错误的。 –

+0

我正在使用google rest api POST /drive/root:/{path_to_item}:/upload.createSession方法这是链接https://dev.onedrive.com/items/upload_large_files.htm –

回答

0

我想创建会话和上传文件时的问题是URL你正在发布。它看起来像这样:

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不知道如何处理那些(因此不好的要求)。

尝试建立URL这样,而不是:

string url = "https://api.onedrive.com/v1.0/drive/root:/" + "Nopbackup" + "/" + fileName +":/upload.createSession"; 

而且我认为事情会更好地为您。

相关问题