我需要使用网站管理员工具中的“元标记”来验证网站的所有权。我在 Vb.net 中使用 Google Webmaster Tool API。以下是代码逻辑。
Dim client As New WebClient
Try
Dim query As String
client.Headers.Add("Authorization: GoogleLogin auth=" + _auth)
client.Headers.Add("GData-Version: 2")
client.Headers.Add("Content-Type", "application/atom+xml")
query = "<atom:entry xmlns:atom=""http://www.w3.org/2005/Atom"" " + _
"xmlns:wt=""http://schemas.google.com/webmasters/tools/2007""> " + _
"<atom:id>https://www.google.com/webmasters/tools/feeds/sites/http%3A%2F%2Ftestwebsite2.demos.classicinformatics.com%2F</atom:id> " + _
"<atom:category scheme='http://schemas.google.com/g/2005#kind' " + _
"term='http://schemas.google.com/webmasters/tools/2007#site-info'/> " + _
"<wt:verification-method type=""metatag"" in-use=""true""/> " + _
"</atom:entry>"
Dim response = client.UploadString("https://www.google.com/webmasters/tools/feeds/sites/http%3A%2F%2Ftestwebsite2.demos.classicinformatics.com%2F", _
"PUT", query)
Catch ex As WebException
End Try
在上面的代码中,上传 API 字符串后,我收到 400 Bad Request 错误,而如果成功,响应应该是站点提要,每个条目都已更新,并且“已验证”元素设置为“真”。