0

I am developing a system to automate the Google site verification using ASP.Net(C#) and I am using DotNetOpenOauth to do the authentication.

I wonder whether there is a way to supply JSON in the request body with scope "https://www.googleapis.com/auth/siteverification" using DotNetOpenOauth? Because when the site verification is been doing, we have to send following JSON with the request.

(using Google OAuth2)

{
  "site": {
    "type": string,
    "identifier": string
  },
  "verificationMethod": string
}
4

1 回答 1

0

I have found the answer by myself. I have added following code to send the JSON body with the request.

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();

If you know any better way to do this, please let me know.

于 2013-07-03T09:21:15.163 回答