看似简单的事情却导致我出错
我已经将自定义标头添加到了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"]
}
现在可以使用了,谢谢。
答案 0 :(得分:1)
CorrelationId
标头和Cache-Control
标头之间的额外返回导致请求被篡改。请求中的标头之间只能有一个换行符。