Atif Khattak
Atif Khattak

Reputation: 169

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

Upvotes: 16

Views: 37102

Answers (8)

ahmetFLacn
ahmetFLacn

Reputation: 11

This has just happened to me to. All I did was to delete this " ↵ " characters at the places shown in the picture.

Upvotes: 1

León Mora
León Mora

Reputation: 81

In my case this happened because I added an extra blanckspace at the end of an environment variable deffinition. That extra space was being taken into account in the route when making a request. Be careful with those extra blanck spaces.

Upvotes: 0

Paul Robson
Paul Robson

Reputation: 210

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.

Upvotes: 21

Jérôme MEVEL
Jérôme MEVEL

Reputation: 7814

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

Upvotes: 3

SkorpEN
SkorpEN

Reputation: 2709

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

Upvotes: 0

Mohammed Osman
Mohammed Osman

Reputation: 4246

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

Upvotes: 0

abo
abo

Reputation: 378

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.

Upvotes: 4

Galti
Galti

Reputation: 137

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.

Upvotes: 1

Related Questions