Skip to content

Latest commit

 

History

History
71 lines (55 loc) · 1.62 KB

index.md

File metadata and controls

71 lines (55 loc) · 1.62 KB

洛谷 API 文档

不方便直接列出的类型定义在 luogu-api.d.ts

对于所有请求:

  • 文本编码为 UTF-8。
  • 头字段 user-agent 的值不能含有子串 python-requests(大小写不敏感)。

对于非 GET 请求:

  • 头字段 referer 的值为 https://www.luogu.com.cn/
  • 需要头字段 x-csrf-token,值为未失效的 CSRF 令牌(除非在请求主体中给出)。

对于响应主体类型为 DataResponse 的请求:

  • 需要参数 _contentOnly(值任意)或头字段 x-luogu-type(值为 content-only)。

目录

范例

GET 请求

列出主题库中标题含有“模板”的题目。

await fetch("https://www.luogu.com.cn/problem/list?type=P&keyword=模板", {
  headers: [
    ["x-luogu-type", "content-only"],
  ],
});

POST 请求

此文档的编者发送一条内容为“Hi”的私信。

await fetch("https://www.luogu.com.cn/api/chat/new", {
  headers: [
    ["content-type", "application/json"],
    ["referer", "https://www.luogu.com.cn/"],
    ["x-csrf-token", document.querySelector("meta[name=csrf-token]").content],
  ],
  body: JSON.stringify({
    user: 206953,
    content: "Hi",
  }),
  method: "POST",
});