手动提交Bing的IndexNow
手动提交Bing的IndexNow
一、生成 API 密钥
访问**Bing IndexNow设置页面**生成随机API密钥和验证文件,然后下载这个文件。。
二、托管您的 API 密钥
将生成的UTF-8密钥文件上传在您网站的任何位置(最好是根目录):
https: //www.example.com/7e6864b3a00747c0acad4b5a188dc4f8.txt
这一步经过我的验证,不放在根目录的话,好像是没用的,所以最好还是放在根目录。
三、手动提交
通过API提交更新的URL:
POST /IndexNow HTTP/1.1
Content-Type: application/json; charset=utf-8
Host: api.indexnow.org
{
"host": "www.example.org",
"key": "7e6864b3a00747c0acad4b5a188dc4f8",
"keyLocation": "https://www.example.org/7e6864b3a00747c0acad4b5a188dc4f8.txt",
"urlList": [
"https://www.example.org/url1",
"https://www.example.org/folder/url2",
"https://www.example.org/url3"
]
}
记得修改key 和keyLocation 相关内容为你刚刚生成的uuid。
四、验证 URL
使用Bing 网站管理员工具验证您的 URL 是否被搜索引擎接收。
五、使用Java提交示例
测试用例:
@Test
void submit(){
List<SitemapUrls> sitemapUrls = SitemapUtil.parseSitemap(
"https://senxxx.icu/sitemap.xml"
);
List<String> urls = new ArrayList<>();
//获取要提交的URL
for(SitemapUrls s : sitemapUrls){
urls.add(s.getLoc());
}
IndexNow indexNow = new IndexNow(
"senxxx.icu",
"3fd602309bbc4418adb0f8a8306589c4",
"https://senxxx.icu/3fd602309bbc4418adb0f8a8306589c4.txt",
urls
);
String jsonStr = JSONUtil.toJsonStr(indexNow);
System.out.println(jsonStr);
//发起POST请求更新URL
HttpResponse execute = HttpUtil.createPost("https://api.indexnow.org/indexnow")
.body(jsonStr)
.header("Content-Type", "application/json")
.execute();
System.out.println(execute.headers());
System.out.println(execute.body());
}
senxxx是我虚拟的一个域名,urls里面是要提交的url集合。
本文是原创文章,采用 CC BY-NC-ND 4.0 协议,完整转载请注明来自 程序员七字节
评论
匿名评论
隐私政策
你无需删除空行,直接评论以获取最佳展示效果