How to judge whether a webpage existed in a fast way
---date: Mar 09, 2016
tags:
- C#
language: English
---
Recently I am coding a app for viewing newspaper. Because there are no API, I have to manually find whether the page ever existed. So I try to look on the Internet, and find a try catch way to judge it:
1 | HttpWebResponse response = null; |
However, I find that GetResponse method now no longer existed in .NET framework 4.5.2. So I find a another one that worked. But it is very slow. So I come up with an idea-using the HTTP head to find out whether it exists, and it is a lot faster:
1 | HttpClient httpClient = new HttpClient(); |