asp.net - Consume Web API haing Action methods with custom name -
i trying consume web api in action method names custome createcustomer(..), getcustomer(...). these annotated [httppost]/[httpget]. not sure how consume using httpclient(). if set following , me call
httpclient client = new httpclient(); client.baseaddress = new uri("http://host/directory/"); client.defaultrequestheaders.accept.add(new mediatypewithqualityheadervalue("application/json")); var response = client.postasjsonasync("api/customer", cutomerobj).result;
it throws 404. if use fiddler , send arequest http://host/directory/api/customer json customer object works perfectly
what missing here? need user post , methods?
you need configure route include action
api/{controller}/{action}/{id}
, make call api/customer/createcustomer
from c#,
var t = new httpclient().getasync("http://localhost:63154/api/userapi/createcustomer").result.content.readasstringasync().result;
Comments
Post a Comment