c# - Cannot call Web API in different project but same solution -
here situation. have 1 solution containing 2 projects: web api , web form. set both projects startup projects. in code behind, call web api this:
private httpresponsemessage downloadfile(int id) { using (var client = new httpclient()) { client.baseaddress = new uri("http://localhost:8096/"); client.defaultrequestheaders.accept.clear(); client.defaultrequestheaders.accept.add(new mediatypewithqualityheadervalue("application/pdf")); httpresponsemessage response = client.getasync("api/document/" + id).result; return response; } }
when click start in visual studio, if web api running on different port webform, "actively refused connection" (as exception said).
so question is: how can make web api accept call without changing port? don't want both projects run on same port. why can't call many external apis?
thanks help.
Comments
Post a Comment