# 创建主题时无法验证 CSRF 令牌的真实性

**URL:** https://meta.discourse.org/t/cant-verify-csrf-token-authenticity-while-creating-topics/234331
**Category:** Development
**Tags:** rest-api
**Created:** [2022年七月28日 22:31 UTC](https://meta.discourse.org/t/cant-verify-csrf-token-authenticity-while-creating-topics/234331 "2022-07-28T22:31:22Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![attj](https://avatars.discourse-cdn.com/v4/letter/a/a698b9/32.png) [@attj](https://meta.discourse.org/u/attj)
#### Post date: [2022年七月28日 22:31 UTC](https://meta.discourse.org/t/cant-verify-csrf-token-authenticity-while-creating-topics/234331/1 "2022-07-28T22:31:22Z")

</div>

我的 curl 命令如下：

```plaintext
curl -X POST 'https://example.com/posts' \
-H "Content-Type: multipart/form-data;" \
--form 'Api-Key="redacted"' \
--form 'Api-Username="redacted"' \
--form 'title="Test topic"' \
--form 'raw="Hey this is a topic."'

```

我收到回复 `["BAD CSRF"]`，生产日志显示“无法验证 CSRF 令牌的真实性”。我查看了此主题 [https://meta.discourse.org/t/bad-csrf-on-creating-new-topic-via-api/89345，但它基本上是由一个拼写错误引起的，所以我猜这里有些不同。我仔细检查了](https://meta.discourse.org/t/bad-csrf-on-creating-new-topic-via-api/89345%EF%BC%8C%E4%BD%86%E5%AE%83%E5%9F%BA%E6%9C%AC%E4%B8%8A%E6%98%AF%E7%94%B1%E4%B8%80%E4%B8%AA%E6%8B%BC%E5%86%99%E9%94%99%E8%AF%AF%E5%BC%95%E8%B5%B7%E7%9A%84%EF%BC%8C%E6%89%80%E4%BB%A5%E6%88%91%E7%8C%9C%E8%BF%99%E9%87%8C%E6%9C%89%E4%BA%9B%E4%B8%8D%E5%90%8C%E3%80%82%E6%88%91%E4%BB%94%E7%BB%86%E6%A3%80%E6%9F%A5%E4%BA%86) api-key 和用户名，它们在网站上仍然是活动的。我很感谢您能提供的任何建议。谢谢！

---

<div class="post-metadata">

### Author: ![Gaurav\_Tewari](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gaurav_tewari/32/260621_2.png) [@Gaurav\_Tewari](https://meta.discourse.org/u/Gaurav_Tewari)
#### Post date: [2022年十一月4日 19:06 UTC](https://meta.discourse.org/t/cant-verify-csrf-token-authenticity-while-creating-topics/234331/2 "2022-11-04T19:06:47Z")

</div>

您好，您的 Curl 请求出现 403 BAD CSRF 错误，因为在 Content-Type 标头中未传递 Api-Key 和 Api-Username。进行此更改即可正常工作。

谢谢  
GT
