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錯誤
不知道您正在調用的服務的細節,但將ContentType作爲ContentTipe並將ContentLength設爲零可能是錯誤的。 –
我正在使用google rest api POST /drive/root:/{path_to_item}:/upload.createSession方法這是鏈接https://dev.onedrive.com/items/upload_large_files.htm –