Using RestSharp to call API running on host header enabled IIS instance

1.7k views Asked by At

I have an IIS server with multiple sites configured. They all serve on port 80 so I use host header configuration to route requests to the correct site. This all works fine when the requests originate from a browser. However, when I call one of the sites (which serves a REST API) using RestSharp I get back an 'unable to resolve address' message. If I switch the API web to another port and stop using host headers it works. Therefore the request I am generating using RestSharp does not comply with what the server expects. ?using Fiddler I have compared a browser request that works against an RestSharp request that does not and have failed to see what's missing or wrong. The RestSharp request does include the HTTP Header 'Host' with the correct value.

1

There are 1 answers

0
Jure On

What do you mean "it works when request comes from a browser"? Does server return html or are you actually calling rest api through browser (for test)? Can you post http headers from browser's request and restsharp's request?
I had similar problem in one of my projects (but getting 404 not found). I found out that adding a header "Accept: application/json" fixed that problem.