'Invalid character in header content ["Host"] Postman

When i try to test api with localhost:[port] it gives the invalid character in header ["Host"] console error. I am using dotnet core webApi. I cross checked the CORS configuration from api end it is fine. The issue is on the Postman side. Postman version: v8.7.0

I have attached the screenshot of the issue



Solution 1:[1]

I also had same incident and I was able to find the error by exporting "My Workspace" content and open it from notepad++. Then change the encoding to "ANSI" from notepad++ (Encoding=> ANSI). You will notice special characters as below,

enter image description here

This can happen when you copy the url and paste in Postman and then try to edit it.

If you are getting this URL from someone what you can ask is to provide exported json file from postman. Then import it to your workspace.

Solution 2:[2]

Taken from question comments. by Fidel Garcia

I created the request again via Add Request menu and it works. I'm not sure if it is a problem with the update and old requests. The old one is still failing.

===================================================

It also worked for me. I created new request with the same parameters and it worked. I created a requested with and wrote the parameters in headers. After wrong requested I changed it to correct one (post request and parameters in body) and got the error. After creating new request with correct configuration (post request parameters in body) it worked correctly.

Solution 3:[3]

In my case: I removed the authentication from Header then I re-enter the authentication credentials again.

Solution 4:[4]

In my case enter after param and path generate error. Exact reason could be found in postman console.

Solution 5:[5]

I thought the issue was in a variable I was using because the error was telling me there's an invalid character in my host https://localhost:4431 which is exactly the value of my variable.

I figured out the invalid character was actually not in my variable but in the rest of the URL in my request.

Turns out, when copying endpoint names from the Swagger of my API, I was also copying an invisible character %E2%80%8B. I saw it when checking the API's console RequestPath:/%E2%80%8BmyEndpoint

Removing this invisible character solved the issue

Solution 6:[6]

I had the same error being reported for any forked or created Postman requests:

Error: Invalid character in header content ["Host"]

The request URL was using a global parameter:

{{BaseUri}}/some/sort/of/resource

In the console logs the following was reported (URLs redacted):

Request Headers
User-Agent: PostmanRuntime/7.29.0
Accept: */*
Cache-Control: no-cache
Postman-Token: 9d14e81d-1e21-44a2-93ed-2758f0ad24fa
Host: my.url.co.uk?
Accept-Encoding: gzip, deflate, br
Connection: keep-alive

Note the ? character at the end of the Host Header.

The global BaseUri parameter did not appear to have a line break at the end of it. However, completely deleting said parameter and recreating it seems to have fixed the issue.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 abo
Solution 2 Galti
Solution 3 Mohammed Osman
Solution 4 SkorpEN
Solution 5 Jérôme MEVEL
Solution 6 Paul Robson