【问题标题】:Google Webmaster SiteVerificatoin with DotNetOpenOauth带有 DotNetOpenOauth 的 Google Webmaster SiteVerificatoin
【发布时间】:2013-07-03 08:45:31
【问题描述】:

我正在开发一个使用 ASP.Net(C#) 自动执行 Google 站点验证的系统,并且我正在使用 DotNetOpenOauth 进行身份验证。

我想知道是否有办法使用 DotNetOpenOauth 在请求正文中提供范围为“https://www.googleapis.com/auth/siteverification”的 JSON?因为在进行站点验证时,我们必须将以下 JSON 与请求一起发送。

(使用 Google OAuth2)

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

【问题讨论】:

    标签: c# asp.net oauth-2.0 dotnetopenauth google-oauth


    【解决方案1】:

    我自己找到了答案。我添加了以下代码来发送带有请求的 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();
    

    如果您知道任何更好的方法,请告诉我。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-01-02
      • 1970-01-01
      • 2021-03-29
      • 1970-01-01
      • 2015-03-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多