PDA

View Full Version : ذخیره محنویات یک آدرس در یک String



gh_fereydonpoor
شنبه 09 اسفند 1382, 16:10 عصر
سلام به همگی
من می خواهم که کد HTML یک آدرس رو بخوانم و در درون یک String ذخیره کنم و سپس بر روی آن پردازش انجام دهم.
کسی میتواند کمکی به من بکند.
ممنون
یا علی

SoheilKH
شنبه 09 اسفند 1382, 18:42 عصر
' Creates an HttpWebRequest for the specified URL.
Dim myHttpWebRequest As HttpWebRequest = CType(WebRequest.Create("http://www.barnamenevis.org/forum/viewtopic.php?t=7625"), HttpWebRequest)
' Sends the request and waits for a response.
Dim myHttpWebResponse As HttpWebResponse = CType(myHttpWebRequest.GetResponse(), HttpWebResponse)
' Calls the method GetResponseStream to return the stream associated with the response.
Dim receiveStream As Stream = myHttpWebResponse.GetResponseStream()
Dim encode As Encoding = System.Text.Encoding.GetEncoding("utf-8")
' Pipes the response stream to a higher level stream reader with the required encoding format.
Dim readStream As New StreamReader(receiveStream, encode)
'Console.WriteLine(ControlChars.Lf + ControlChars.Cr + "Response stream received")
Response.Write(ControlChars.Lf + ControlChars.Cr + "Response stream received")
Dim read(256) As [Char]
' Reads 256 characters at a time.
Dim count As Integer = readStream.Read(read, 0, 256)
Console.WriteLine("HTML..." + ControlChars.Lf + ControlChars.Cr)
While count > 0
' Dumps the 256 characters to a string and displays the string to the console.
Dim str As New [String](read, 0, count)
'Console.Write(str)
Response.Write(str)
count = readStream.Read(read, 0, 256)
End While
Response.Write("")
'Console.WriteLine("")
' Releases the resources of the Stream.
readStream.Close()
' Releases the resources of the response.
myHttpWebResponse.Close()

منبع MSDN

gh_fereydonpoor
یک شنبه 10 اسفند 1382, 10:14 صبح
سلام سهیل جان دستت درد نکنه خیلی باحال بود کلی حال کردم.
ممنون مرسی انشا الله که جبران کنیم
1 در دنیا 100 در آخرت ببری.
یا علی

SoheilKH
دوشنبه 11 اسفند 1382, 03:15 صبح
:wink: :wink:

M.mojaddady@gmail.com
شنبه 20 مرداد 1386, 21:54 عصر
ممکنه لطف کنید کد فو را در C# هم بذارین