a7m3dalbalawi

HTWS - Tut 1

May 27th, 2017
360
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 2.14 KB | None | 0 0
  1. Imports System.IO
  2. Imports System.Net ' نستدعي فضاء الـ Net
  3. Imports System.Text
  4.  
  5. Public Class Form1
  6.     ' نقوم بكتابة Function
  7.     ' مُخصص للإرسال فقط وتلقي الـ Response
  8.     ' ومُعالجة البيانات المُتلقية من الموقع .
  9.     Function SendData(ByRef username As String, ByRef password As String) As String
  10.         Dim Request As HttpWebRequest = HttpWebRequest.Create("http://localhost/dorah/") ' هُنا نُنشئ الإتصال
  11.         Request.Method = "POST" ' هُنا ايضا قمنا بتحديد نوع الإتصال
  12.         Request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:53.0) Gecko/20100101 Firefox/53.0"
  13.         Request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
  14.         Request.Headers.Add("Accept-Language: en-US,en;q=0.5")
  15.         Request.ContentType = "application/x-www-form-urlencoded"
  16.         Request.Referer = "http://localhost/dorah/"
  17.         ' الان نقوم بتعريف مُتغير يحمل قيم البيانات المُرسلة .
  18.         Dim PostData As String = "username=" & username & "&password=" & password & "&submit=%D8%AA%D8%B3%D8%AC%D9%8A%D9%84+%D8%A7%D9%84%D8%AF%D8%AE%D9%88%D9%84"
  19.         Dim ByteArray As Byte() = Encoding.Default.GetBytes(PostData)
  20.         Request.ContentLength = byteArray.Length
  21.         Dim DataStream As Stream = Request.GetRequestStream()
  22.         DataStream.Write(ByteArray, 0, ByteArray.Length)
  23.         DataStream.Close()
  24.         Dim Response As HttpWebResponse = Request.GetResponse()
  25.         DataStream = Response.GetResponseStream()
  26.         Dim Reader As New StreamReader(DataStream)
  27.         Dim ResponseFromServer As String = Reader.ReadToEnd
  28.         Return ResponseFromServer
  29.     End Function
  30.     Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  31.         Dim Response As String = SendData(TextBox1.Text, TextBox2.Text) ' قُمنا بإستدعاء الفنكشن وايضا وضع المتطلبات حسب قيم مربع النصوص التالي
  32.         MsgBox(Response, MsgBoxStyle.Information, "Information")
  33.     End Sub
  34. End Class
Advertisement
Add Comment
Please, Sign In to add comment