-
Notifications
You must be signed in to change notification settings - Fork 0
/
Check.cs
54 lines (45 loc) · 1.34 KB
/
Check.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Text;
#pragma warning disable SYSLIB0014 // 类型或成员已过时
namespace PlayListLib
{
public class CheckClient
{
private static HttpWebRequest response;
public static bool ExistanceCheck(string url)
{
if (string.IsNullOrWhiteSpace(url)) return false;
url = url.Trim();
if (url.StartsWith("\"") && url.EndsWith("\"")) url = url.Substring(1, url.Length - 2);
try
{
response = WebRequest.CreateHttp(url);
response.Timeout = 1000;
var res = (HttpWebResponse)response.GetResponse();
var success = res.StatusCode == HttpStatusCode.OK;
res.Close();
return success;
}
catch
{
try
{
if (Path.IsPathRooted(url)) return File.Exists(url);
}
catch { }
}
//(Exception ex) { Console.WriteLine(ex); }
finally
{
response = null;
}
return false;
}
}
}
#pragma warning restore SYSLIB0014 // 类型或成员已过时