我發現我自己的答案。我添加了以下代碼以發送請求的JSON正文。
WebRequest request = WebRequest.Create("https://www.googleapis.com/siteVerification/v1/token?access_token=" + Uri.EscapeDataString(authState.AccessToken));
string path = HostingEnvironment.MapPath(@"~/App_Data/SiteVerificatoin.json");
MemoryStream ms = new MemoryStream();
FileStream fileStreem = new FileStream(path, FileMode.Open, FileAccess.Read);
byte[] bytes = new byte[fileStreem.Length];
fileStreem.Read(bytes, 0, (int)fileStreem.Length);
ms.Write(bytes, 0, (int)fileStreem.Length);
request.ContentType = "application/json";
request.Method = "POST";
request.ContentLength = ms.Length;
ms.Seek(0, SeekOrigin.Begin);
using (Stream requestStream = request.GetRequestStream())
{
ms.CopyTo(requestStream);
}
WebResponse response = request.GetResponse();
如果你知道更好的方法來做到這一點,請讓我知道。