25-10-13, 01:52 PM
(آخر تعديل لهذه المشاركة : 25-10-13, 01:53 PM {2} بواسطة الشاكي لله.)
تفضل
الاستعمال
PHP كود :
''' <summary>
''' التحقق من وجود ملف على رابط معين
''' اذا كان قيمة غير صحيحة فيعني ذلك
''' 404 not found
''' </summary>
''' <param name="url"></param>
''' <returns></returns>
Public Shared Function IsFileAlive(url As String) As Boolean
If Not url.ToLower().StartsWith("http://") Then
Throw New Exception("Schemeيجب ان يبدأ الرابط ب")
End If
Try
Dim rq As HttpWebRequest = DirectCast(WebRequest.Create(url), HttpWebRequest)
rq.Method = WebRequestMethods.Http.Head
Using rs As HttpWebResponse = DirectCast(rq.GetResponse(), HttpWebResponse)
If rs.StatusCode = HttpStatusCode.OK Then
Return True
Else
Return False
End If
End Using
Catch ex As Exception
If ex.Message = "The remote server returned an error: (404) Not Found." Then
Return False
Else
Throw New Exception(ex.Message)
End If
End Try
End Function
الاستعمال
PHP كود :
Try
Dim s As Boolean = IsFileOnServer("http://www.google.com/kwskwqkdqw")
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try

