Resolve Bad Request Invalid Hostname via IP address

RiCo 技術農場
Nov 8 · 3 min read

當使用VS IDE進行web api專案debug階段,預設使用IIS Express並host,hostname預設也使用localhost,如下圖

但有時候我需要在其他VM打webapi進行測試,當我把localhost改為IP address,

chrome會出現Bad request-invalid hostname錯誤

400 bad request

查看IIS Express中的該站台,確實只有binding localhost

要能正確使用IP address,我只需要多新增一組IP的綁定即可,

針對該站台進行組態修改,新增以下內容

選擇顯示所有應用程式
<binding protocol="http" bindingInformation="192.168.137.1:5110:*" />
修改後並重新啟動,就可以看到多一組IP的綁定
多了一組IP的綁定

透過chrome也能正常送出http request

參考

IIS Express Overview

Bad Request-Invalid Hostname

RiCo’s Note

C#/SQL Server/Azure/NetCore/Angular/Kafka….

RiCo 技術農場

Written by

分享工作上實戰經驗,如SQL Server,NetCore,C#,WEBApi,Kafka,Azure…等,Architect,Software Engineer, Technical Manger,Writer and Speaker

RiCo’s Note

C#/SQL Server/Azure/NetCore/Angular/Kafka….

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade