【问题标题】:Custom headers in aspnetcore 2.1aspnetcore 2.1 中的自定义标头
【发布时间】:2018-08-22 16:41:51
【问题描述】:

看似简单的事情却导致我出错

我在我的帖子中添加了一个自定义标头到 webapi aspnetcore 2.1 端点,但是当标头添加到请求中时,我在邮递员中得到了这个

Could not get any response
There was an error connecting to http://localhost:3481/api/account/register.

当我删除标题时,它按预期工作。

自定义标题是 CorrelationId 这是帖子

POST //api/account/register HTTP/1.1
Host: localhost:3481
Content-Type: application/json
CorrelationId: 0bdf0a56-fe94-479c-a6db-4b93ad81ad6c

Cache-Control: no-cache
Postman-Token: 7324c922-2911-4ac4-9ede-6401199f4f87

{
"firstName": "dev 23",
  "lastName": "dev",
  "username": "devuser23",
  "email": "devuser23@dev.com",
  "phoneNumber": "6468842757",
  "password": "!Password1",
  "confirmPassword": "!Password1",
  "OneSignalUserId":"teststring",
  "PushToken":"anotherteststring",
  "Roles":["Customer"]
}

我不确定它的标题有什么问题。

我检查了日志和应用洞察,它们甚至没有显示正在发出的请求或引发任何异常。

编辑 我回去查看邮递员中的值的输入框,它确实有返回,这导致了额外的行。下面是我删除空间后的样子。

POST //api/account/register HTTP/1.1
Host: localhost:3481
Content-Type: application/json
TableTopCorrelationId: 0bdf0a56-fe94-479c-a6db-4b93ad81ad6c
Cache-Control: no-cache
Postman-Token: 12a4c705-9658-412f-bfd2-5df75d4b0d70

{
"firstName": "dev 23",
  "lastName": "dev",
  "username": "devuser23",
  "email": "devuser23@dev.com",
  "phoneNumber": "6468842757",
  "password": "!Password1",
  "confirmPassword": "!Password1",
  "OneSignalUserId":"teststring",
  "PushToken":"anotherteststring",
  "Roles":["Customer"]
}

现在可以使用了,谢谢。

【问题讨论】:

  • CorrelationId 标头和 Cache-Control 标头之间的多余空格是复制粘贴错误,还是 字面意思发送的内容。如果是后者,那是你的问题。
  • @ChrisPratt,我确实是从 Postman 那里复制过来的。但这可能是我复制correlationId值时的错误复制和粘贴。谢谢,我现在就试试
  • @ChrisPratt 如果让你的评论成为答案,我会将其标记为正确

标签: asp.net-core custom-headers


【解决方案1】:

CorrelationId 标头和 Cache-Control 标头之间的额外返回导致请求被破坏。请求的标头之间可能只有一个换行符。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多