asp.net mvc - How to get the JSON string from a Web API response -
i have asp.net mvc 4 application have controller whith action recieves xhr requests , returns json. in action want make call web api, recieve response json , use json string actions return value.
(and i'm not allowed call web api directly javascript, need go via server)
i manage make request web api can't figure out how read out json string.
here method:
public actionresult index() { string ret = ""; httpclient client = new httpclient(); client.baseaddress = new uri("http://localhost:8080/"); client.defaultrequestheaders.accept.add( new mediatypewithqualityheadervalue("application/json")); httpresponsemessage response = client.getasync("api/stuff").result; if (response.issuccessstatuscode) { // how json string out of response object? //ret = response.?? } else { } return content(ret, "application/json"); }
how this.
string json = await response.content.readasstringasync();
Comments
Post a Comment