asp.net-corecustom-headers

Custom headers in aspnetcore 2.1


What seems like a simple thing to do is causing me errors

I have added a custom header to my post to webapi aspnetcore 2.1 endpoint, but when the header is added to the request I get this in postman

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

when I remove the header it works as expected.

the custom header is CorrelationId this is the post

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"]
}

Im not sure what the problem is with the header that it.

I have checked logs and app insights which don't even show the request being made or throw any exceptions happened.

EDIT I went back and looked entry box for the value in postman and it did have a return on it, which caused the extra line. Below is what it looks like once I removed the space.

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"]
}

it works now thanks.


Solution

  • The extra return between your CorrelationId header and the Cache-Control header is causing the request to be mangled. There may only be a single line feed between headers in a request.