【发布时间】:2023-03-06 12:54:02
【问题描述】:
我正在尝试将文件的 MIME 类型更改为 in the documentation 中所述的 "application/vnd.google-apps.folder"。但是,当我发出网络请求时,不会引发错误,但 mime 类型不会改变。
这是我的代码:
public string MimeType
{
get
{
dynamic data = JsonConvert.DeserializeObject(JsonMetadata); //the json of the fileID
return data.mimeType;
}
set
{
RandomMethods.CreateRequest( //custom method for creating HttpWebRequest
"PATCH", //method
string.Format("https://www.googleapis.com/drive/v3/files/{0}?access_token={1}", FileID, Auth.AccessToken), //url
"application/json", //content type
"{ \"mimeType\": \"" + value + "\"}" //body
).GetResponse().Dispose();
}
}
get 可以正常工作,而set 不能正常工作。这让我感到困惑,因为我的 Name 变量可以正常工作,并且使用完全相同的方法,只是名称被换掉了。
这是我使用的CreateRequest方法:
public static HttpWebRequest CreateRequest(string method, string url, string contentType, string body)
{
var req = WebRequest.Create(url) as HttpWebRequest;
req.Method = method;
req.ContentType = contentType;
byte[] data = Encoding.UTF8.GetBytes(body);
req.ContentLength = data.Length;
using (Stream stream = req.GetRequestStream())
stream.Write(data, 0, data.Length);
return req;
}
【问题讨论】:
标签: c# google-api google-drive-api httpwebrequest mime-types