# 如何在 Api-Username 标头中处理非 ASCII 字符？

**URL:** https://meta.discourse.org/t/how-to-handle-non-ascii-characters-in-api-username-header/393646
**Category:** Development
**Created:** [2026年一月16日 06:59 UTC](https://meta.discourse.org/t/how-to-handle-non-ascii-characters-in-api-username-header/393646 "2026-01-16T06:59:54Z")
**Posts on this page:** 1
**Showing post:** 3

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [2026年一月16日 15:03 UTC](https://meta.discourse.org/t/how-to-handle-non-ascii-characters-in-api-username-header/393646/3 "2026-01-16T15:03:52Z")

</div>

感谢 @xbd 的发现 - 这将通过

> <https://github.com/discourse/discourse/pull/37177>
>
> Refactors username lookups throughout the codebase to consistently use \`User.nor…malize\_username\`, \`User.find\_by\_username\`, or the new \`User.where\_username\` scope.
> 
> Previously, username lookups were inconsistent - some used \`.downcase\`, others used \`normalize\_username\`. This consolidation ensures all lookups go through the same normalization logic.
> 
> Changes:
> 
> \- Adds \`User.where\_username\` scope for multi-user lookups
> \- Replaces manual \`.downcase\` lookups with \`find\_by\_username\` or \`where\_username\`
> \- Updates ILIKE/LIKE queries to use \`username\_lower\` with normalized input
> \- Fixes a pre-existing SQL injection vulnerability in search user ordering
> \- Updates bulk import scripts and migrations for consistency
> 
> Ref - https://meta.discourse.org/t/393646

修复

但在同时…

> [@xbd](#):
>
> - 使用用户 ID 代替（如果是，使用哪个标头名称）？

…您可以通过 `Api-User-Id` 标头使用用户 ID（如果您有的话，实际上更推荐使用用户 ID 而不是用户名）

```bash
curl -X GET "https://your-discourse.com/admin/users.json" \
  -H "Api-Key: your-api-key" \
  -H "Api-User-Id: 123"

```

---

_[View the full topic](https://meta.discourse.org/t/how-to-handle-non-ascii-characters-in-api-username-header/393646)._
