我正在将文件上传到Google云端硬盘(https://developers.google.com/drive/manage-uploads) 当我点击上传按钮时,我收到错误:“403 Forbidden” 我的代码:
string access_token = "ya29.1.AADtN_USZWM44X_WIxgAr-f6NcdQ-XG8TEturcGXRADzdeVvXZhSVR8d6Qf98veHqy3ZGLQ";
string result = "";
byte[] buffer = uploader.FileBytes;
HttpWebRequest req = (HttpWebRequest)WebRequest.Create("https://www.googleapis.com/upload/drive/v2/files?uploadType=media");
req.Method = "POST";
req.ContentType = "image/jpeg";
req.ContentLength = buffer.Length;
req.Headers["Authorization"] = "Bearer "+access_token;
Stream strm = req.GetRequestStream();
strm.Write(buffer, 0, buffer.Length);
strm.Close();
HttpWebResponse webResponse = (HttpWebResponse)req.GetResponse();//Get error here
if (webResponse.StatusCode == HttpStatusCode.OK)
{
Stream responseStream = webResponse.GetResponseStream();
StreamReader responseStreamReader = new StreamReader(responseStream);
result = responseStreamReader.ReadToEnd();//parse token from result
}
lblMessage.Text = result;
webResponse.Close();
请帮助我!