c# - How to make HTTP calls, using ASP.NET MVC? -
c# - How to make HTTP calls, using ASP.NET MVC? -
i'm new programming, , learning asp.net mvc 5. i can't find how create http calls/requests websites in tutorials, nor on stackoverflow (or maybe exists, can't find it; not quite sure what search, though have tried).
what i'm trying do:
i'm trying practise making http calls (...if it's called) simple asp.net mvc web application. this, attempting weather details openweathermap. can by:
add next parameter request: appid=apikey example: api.openweathermap.org/data/2.5/forecast/city?id=524901&appid=1111111111my understanding, learning:
the controller 1 create above http call.my question:
how create http request, in asp.net mvc?
use system.net.http.httpclient
.
you can basic reading website using following:
using (var client = new httpclient()) { var uri = new uri("http://www.google.com/"); var response = await client.getasync(uri); string textresult = await response.content.readasstringasync(); }
you may want create sure test response.issuccessstatuscode
(checks http 200 result) create sure result expect before parse it.
c# asp.net-mvc
Comments
Post a Comment