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=1111111111

my 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

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -