api - c# Webrequest Webresponse getting 403: forbidden -


i'm trying more experience c# want make small app using windows forms in visual studio. app should rocket launch times https://launchlibrary.net , use them in countdown. have no experience in getting data internet using c#, have no idea if i'm doing right. code came after research.

the problem @ line: webresponse response = request.getresponse();

i'm getting below error-

"the remote server returned error (403) forbidden"

if me or point me in right direction happy.

thank you

            // create request url.              webrequest request = webrequest.create("https://launchlibrary.net/1.2/agency/5");             request.method = "get";             // response.             webresponse response = request.getresponse();             // display status.             messagebox.show(((httpwebresponse)response).statusdescription);             // stream containing content returned server.             stream datastream = response.getresponsestream();             // open stream using streamreader easy access.             streamreader reader = new streamreader(datastream);             // read content.             string responsefromtheserver = reader.readtoend();             // display content             messagebox.show(responsefromtheserver);             // clean streams , response.             reader.close();             response.close(); 

this sample using webclient, must set user-agent header, otherwise 403:

using (var webclient = new webclient()) {   webclient.headers.add("user-agent", "mozilla/5.0 (windows nt 10.0; wow64) applewebkit/537.36 (khtml, gecko) chrome/51.0.2704.103 safari/537.36");   var response = webclient.downloadstring("https://launchlibrary.net/1.2/agency/5");   messagebox.show(response); } 

Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -