2016-05-14 51 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"; 

而且我認爲事情會更好地爲您。

相關問題