http status code 404 - Adding a catch to ignore 404 web exception (C#) -


i writing app scrape website keywords. running issue if try read page not follow through 404 (not problem).

however when app encounters 404 web exception not continue. know need try , catch can't quite figure out how add 404 webexception catch without errors. here code snippet issue: think problem not know put try/catch have return source; error not returning value when add catch.

string url = string.format(@"http://127.0.0.1/website/" + searchterm);  httpwebrequest req = (httpwebrequest)httpwebrequest.create(url); req.method = "get"; req.useragent = "mozilla/5.0 (windows; u; msie 9.0; windows nt 9.0; en-us))";  uri target = req.requesturi; string source;  using (streamreader reader = new streamreader(req.getresponse().getresponsestream())) {     source = reader.readtoend(); } return source; 

thanks alex k:

i forgot declare source = ""; @ top instead of bottom.

thank alex k!


Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

html - Why is a table with width of 75% wider than three tables which total 99%? -